Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set custom labels on y axis

I'm using the Google Chart API (not Google Image Chart) to create a line chart with dates on the x axis (bottom) and numbers on the y axis (left). I want to add an r axis (right) with string labels.

If I understand the following page correctly, it's only possible to have strings on the major axis (x axis for line chart). The minor axes (y and r axes) only accepts continuous values (like numbers) and not discrete values (like strings).

Customizing Axes

In Google Image Charts it is possible to work around this by assigning the string data to a value (say from 0 to 100) and assign custom string labels to the axis using the chxl parameter. This is especially easy if the data is evenly spaced.

I've looked at the API reference but can't find anything similar when using the Google Chart API.

Does anyone know if it's possible?

Best regards, JP

like image 271
user1119112 Avatar asked Mar 17 '12 09:03

user1119112


1 Answers

The simplest approach of all is to add the following to your graph options:

vAxis: { ticks: [{ v: 0, f: 'Zero'}, {v: 1, f: 'One'}, {v: 2, f: 'Two'}]}

In this example, I'm indicating that "Zero" should be displayed instead of 0, "One" instead of 1, etc.

like image 71
Greg Avatar answered Sep 29 '22 16:09

Greg