Skip to content

Instantly share code, notes, and snippets.

@winston
Created July 1, 2011 06:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save winston/1057968 to your computer and use it in GitHub Desktop.
Save winston/1057968 to your computer and use it in GitHub Desktop.
GoogleVisualr Gem - Pie Chart Creation Example
# http://code.google.com/apis/chart/interactive/docs/gallery/piechart.html#Example
def pie_chart
data_table = GoogleVisualr::DataTable.new
data_table.new_column('string', 'Task')
data_table.new_column('number', 'Hours per Day')
data_table.add_rows(5)
data_table.set_cell(0, 0, 'Work' )
data_table.set_cell(0, 1, 11 )
data_table.set_cell(1, 0, 'Eat' )
data_table.set_cell(1, 1, 2 )
data_table.set_cell(2, 0, 'Commute' )
data_table.set_cell(2, 1, 2 )
data_table.set_cell(3, 0, 'Watch TV' )
data_table.set_cell(3, 1, 2 )
data_table.set_cell(4, 0, 'Sleep' )
data_table.set_cell(4, 1, 7 )
opts = { :width => 400, :height => 240, :title => 'My Daily Activities', :is3D => true }
@chart = GoogleVisualr::Interactive::PieChart.new(data_table, opts)
end
<div id='chart'></div>
<%= render_chart @chart, 'chart' %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment