winston / google_visualr

A Ruby Gem for the Google Visualization API. Write Ruby code. Generate Javascript. Display a Google Chart.
http://googlevisualr.heroku.com
MIT License
428 stars 100 forks source link

Add material charts. #95

Closed winston closed 9 years ago

winston commented 9 years ago

Add material charts for the following:

Fixes #87, #85. Supercedes #88.

To use material charts, just pass in the material: true as an option when creating a chart.

Example:

data_table = GoogleVisualr::DataTable.new
    data_table.new_column('string', 'Year')
    data_table.new_column('number', 'Sales')
    data_table.new_column('number', 'Expenses')
    data_table.add_rows(4)
    data_table.set_cell(0, 0, '2004')
    data_table.set_cell(0, 1, 1000)
    data_table.set_cell(0, 2, 400)
    data_table.set_cell(1, 0, '2005')
    data_table.set_cell(1, 1, 1170)
    data_table.set_cell(1, 2, 460)
    data_table.set_cell(2, 0, '2006')
    data_table.set_cell(2, 1, 660)
    data_table.set_cell(2, 2, 1120)
    data_table.set_cell(3, 0, '2007')
    data_table.set_cell(3, 1, 1030)
    data_table.set_cell(3, 2, 540)

    opts   = { 
      :width => 400, :height => 240, 
      :title => 'Company Performance', 
      vAxis: {title: 'Year', titleTextStyle: {color: 'red'}},
      :material => true
    }
    @chart = GoogleVisualr::Interactive::BarChart.new(data_table, opts)

You can also set material to true after creation of the chart like so:

    opts   = { 
      :width => 400, :height => 240, 
      :title => 'Company Performance', 
      vAxis: {title: 'Year', titleTextStyle: {color: 'red'}}
    }
    @chart = GoogleVisualr::Interactive::BarChart.new(data_table, opts)
    @chart.material = true