Last Updated: May 15, 2019
·
13.52K
· ireneuszskrobis

Setting range, step and format for vertical axis in google_visualr

If you want to set range for a chart, for example to display on vertical axis only numbers from 0 to 3, then you can use this syntax:

vAxis: {viewWindow: {min: 0, max: 3}}

Another thing is when you want to define a step to display only whole numbers, eg: 0, 1, 2, 3. You can't do this the straight way, but you can set the number of gridlines (in this case you will need four of them):

vAxis: {gridlines: {count: 4}}

The last thing you can do is to display only integer numbers (without default decimal values after dot), you can achieve that by adding format option:

vAxis: {:format => "#"}

The complete example looks like this:

data_table = GoogleVisualr::DataTable.new
data_table.new_column('string', 'Day')
data_table.new_column('number', 'Happiness', (0..3))
data_table.add_rows(current_user.happiness_statistics)
options = {height: 400, title: 'Your last 30 days', vAxis: { viewWindow: {min: 0, max: 3}, :format => "#", gridlines: {count: 4}}}
chart = GoogleVisualr::Interactive::AreaChart.new(data_table, options)