Created
July 1, 2011 06:12
-
-
Save winston/1057968 to your computer and use it in GitHub Desktop.
GoogleVisualr Gem - Pie Chart Creation Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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