Skip to content

Instantly share code, notes, and snippets.

@winston
Created April 2, 2010 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save winston/353018 to your computer and use it in GitHub Desktop.
Save winston/353018 to your computer and use it in GitHub Desktop.
GoogleVisualr::BarChart Creation Example
<div id='chart'></div>
<%= @chart.render('chart') %>
# http://code.google.com/apis/visualization/documentation/gallery/barchart.html#Example
def bar_chart
@chart = GoogleVisualr::BarChart.new
@chart.add_column('string', 'Year')
@chart.add_column('number', 'Sales')
@chart.add_column('number', 'Expenses')
@chart.add_rows(4)
@chart.set_value(0, 0, '2004')
@chart.set_value(0, 1, 1000)
@chart.set_value(0, 2, 400)
@chart.set_value(1, 0, '2005')
@chart.set_value(1, 1, 1170)
@chart.set_value(1, 2, 460)
@chart.set_value(2, 0, '2006')
@chart.set_value(2, 1, 1500)
@chart.set_value(2, 2, 660)
@chart.set_value(3, 0, '2007')
@chart.set_value(3, 1, 1030)
@chart.set_value(3, 2, 540)
options = { :width => 400, :height => 240, :title => 'Company Performance', :is3D => true }
options.each_pair do | key, value |
@chart.send "#{key}=", value
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment