Skip to content

Instantly share code, notes, and snippets.

@winston
Created April 4, 2010 10:49
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/355312 to your computer and use it in GitHub Desktop.
Save winston/355312 to your computer and use it in GitHub Desktop.
GoogleVisualr::LineChart Creation Example
# http://code.google.com/apis/visualization/documentation/gallery/linechart.html#Example
def line_chart
@chart = GoogleVisualr::LineChart.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', :legend => 'bottom' }
options.each_pair do | key, value |
@chart.send "#{key}=", value
end
end
<div id='chart'></div>
<%= @chart.render('chart') %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment