Skip to content

Instantly share code, notes, and snippets.

@winston
Created January 22, 2012 09:11
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/1656350 to your computer and use it in GitHub Desktop.
Save winston/1656350 to your computer and use it in GitHub Desktop.
GoogleVisualr Gem - DataTabel with Roles Example
# http://code.google.com/apis/chart/interactive/docs/roles.html
def roles
data_table = GoogleVisualr::DataTable.new
data_table.new_column('string', 'Month')
data_table.new_column('number', 'Sales')
# Columns with role definition
data_table.new_column('number' , nil, nil, 'interval')
data_table.new_column('number' , nil, nil, 'interval')
data_table.new_column('string' , nil, nil, 'annotation')
data_table.new_column('string' , nil, nil, 'annotationText')
data_table.new_column('boolean' , nil, nil, 'certainty')
data_table.add_rows([
['April', 1000, 900 , 1100, 'A', 'Stolen data' , true],
['May' , 1170, 1000, 1200, 'B', 'Coffee spill' , true],
['June' , 660 , 550 , 800 , 'C', 'Wampus attack', true],
['July' , 1030, nil , nil , nil, nil , false]
])
opts = { :width => 600, :height => 400, :title => 'Sales', :legend => 'none' }
@chart = GoogleVisualr::Interactive::LineChart.new(data_table, opts)
end
<div id='chart'></div>
<%= render_chart @chart, 'chart' %>
@vijayprasad20
Copy link

Hi Winston,

First of all, I want to thanks fr making such a nice tool for graphical representation of data. I used this gem in my application and i am stuck with one problem , Actually i want to block the Line chart for negative value of vAxis.

I have set minvalue for vAxis ({ :title=>"Instance",:minValue => 0 }) it works fine of value > 0 but whenever the value of vAxis become zero vAxis range start from -1 ,-0.5, 0 upto 1 which creates a problem for me. I want start vAxis from default value = 0. Please help me for if you have any idea.

Thanks,
Vijay Prasad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment