Skip to content

Instantly share code, notes, and snippets.

@winston
winston / controller.rb
Created July 1, 2011 09:03
GoogleVisualr Gem - Constructor Example
##############################
# Table with Constructor Format
data_table = GoogleVisualr::DataTable.new({
:cols => [ { :id => 'A', :label => 'NEW A' , :type => 'string' },
{ :id => 'B', :label => 'B-label', :type => 'number' },
{ :id => 'C', :label => 'C-label', :type => 'date' }
],
:rows => [ { :c => [ {:v => 'a'}, {:v => 1.0, :f => 'One'} , {:v => Date.parse('2008-02-28 00:31:26'), :f => '2/28/08 12:31 AM'} ] },
{ :c => [ {:v => 'b'}, {:v => 2.0, :f => 'Two'} , {:v => Date.parse('2008-03-30 00:31:26'), :f => '3/30/08 12:31 AM'} ] },
{ :c => [ {:v => 'c'}, {:v => 3.0, :f => 'Three'}, {:v => Date.parse('2008-04-30 00:31:26'), :f => '4/30/08 12:31 AM'} ] }
@winston
winston / controller.rb
Created July 1, 2011 06:30
GoogleVisualr Gem - Number Formatter Creation Example
##############################
# Table with Number Format
data_table_5 = GoogleVisualr::DataTable.new
data_table_5.new_column('string', 'Department' )
data_table_5.new_column('number', 'Revenues Change' )
data_table_5.add_rows([
['Shoes' , 10700 ],
['Sports' , -15400],
['Toys' , 12500 ],
['Electronics', -2100 ],
@winston
winston / controller.rb
Created July 1, 2011 06:29
GoogleVisualr Gem - Date Formatter Creation Example
##############################
# Table with Date Format
data_table_4 = GoogleVisualr::DataTable.new
data_table_4.new_column('string', 'Employee Name')
data_table_4.new_column('date', 'Start Date (L)' )
data_table_4.new_column('date', 'Start Date (M)' )
data_table_4.new_column('date', 'Start Date (S)' )
data_table_4.add_rows([
['Mike' , Date.parse('2008-02-28 00:31:26'), Date.parse('2008-02-28 00:31:26'), Date.parse('2008-02-28 00:31:26') ],
['Bob' , Date.parse('2007-06-01 00:00:00'), Date.parse('2007-06-01 00:00:00'), Date.parse('2007-06-01 00:00:00') ],
@winston
winston / controller.rb
Created July 1, 2011 06:27
GoogleVisualr Gem - Color Formatter Creation Example
##############################
# Table with Color Format
data_table_3 = GoogleVisualr::DataTable.new
data_table_3.new_column('string', 'Department' )
data_table_3.new_column('number', 'Revenues Change' )
data_table_3.add_rows([
['Shoes' , 10700 ],
['Sports' , -15400],
['Toys' , 12500 ],
['Electronics', -2100 ],
@winston
winston / controller.rb
Created July 1, 2011 06:26
GoogleVisualr Gem - Bar Formatter Creation Example
##############################
# Table with Bar Formatter
data_table_2 = GoogleVisualr::DataTable.new
data_table_2.new_column('string', 'Department' )
data_table_2.new_column('number', 'Revenues Change' )
data_table_2.add_rows([
['Shoes' , 10700 ],
['Sports' , -15400],
['Toys' , 12500 ],
['Electronics', -2100 ],
@winston
winston / controller.rb
Created July 1, 2011 06:24
GoogleVisualr Gem - Arrow Formatter Creation Example
##############################
# Table with Arrow Formatter
data_table_1 = GoogleVisualr::DataTable.new
data_table_1.new_column('string', 'Department' )
data_table_1.new_column('number', 'Revenues Change' )
data_table_1.add_rows([
['Shoes' , { :v => 12 , :f => '12.0%' }],
['Sports' , { :v => -7.3 , :f => '-7.3%' }],
['Toys' , { :v => 0 , :f => '0%' }],
['Electronics', { :v => -2.1 , :f => '-2.1%' }],
@winston
winston / controller.rb
Created July 1, 2011 06:14
GoogleVisualr Gem - Table Creation Example
# http://code.google.com/apis/chart/interactive/docs/gallery/table.html#Example
def table
data_table = GoogleVisualr::DataTable.new
data_table.new_column('string' , 'Name')
data_table.new_column('number' , 'Salary')
data_table.new_column('boolean' , 'Full Time Employee')
data_table.add_rows(4)
data_table.set_cell(0, 0, 'Mike' )
data_table.set_cell(0, 1, {:v => 10000, :f => '$10,000'})
@winston
winston / controller.rb
Created July 1, 2011 06:13
GoogleVisualr Gem - Scatter Chart Creation Example
# http://code.google.com/apis/chart/interactive/docs/gallery/scatterchart.html#Example
def scatter_chart
data_table = GoogleVisualr::DataTable.new
data_table.new_column('number', 'Age')
data_table.new_column('number', 'Weight')
data_table.add_rows(6)
data_table.set_cell( 0, 0, 8 )
data_table.set_cell( 0, 1, 12 )
data_table.set_cell( 1, 0, 4 )
@winston
winston / controller.rb
Created July 1, 2011 06:12
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' )
@winston
winston / controller.rb
Created July 1, 2011 06:10
GoogleVisualr Gem - Org ChartCreation Example
# http://code.google.com/apis/chart/interactive/docs/gallery/orgchart.html#Example
def org_chart
data_table = GoogleVisualr::DataTable.new
data_table.new_column('string', 'Name' )
data_table.new_column('string', 'Manager')
data_table.new_column('string', 'ToolTip')
data_table.add_rows( [
[ {:v => 'Mike', :f => 'Mike<div style="color:red; font-style:italic">President</div>' }, '' , 'The President' ],
[ {:v => 'Jim' , :f => 'Jim<div style="color:red; font-style:italic">Vice President<div>'}, 'Mike', 'VP' ],