aopki
aopki

Reputation: 310

Google charts Y-axis step

I'm working on a project using google data visualization API and I'm trying to show a chart illustrating the numbers of visits of users during the last week . the problem is that this number is always an integer and greater or equal to 0 but on my chart the Y-axis show decimal numbers . how can I configure the options array to get only integers ?

enter image description here

Upvotes: 0

Views: 2870

Answers (1)

spenibus
spenibus

Reputation: 4409

From How to show only integers (no decimals) in chart API x/y-axis labels, user asgallant suggests this:

vAxis: {
    format: '#'
}

In that same thread, user Daniel LaLiberte says this:

If you specify a format of '#' you will only see only whole integer values. But if a value that is rounded is not close to an integer, the tick will appear to be in the wrong position, or the label will be wrong for the tick.

The Google Charts API assumes you want 5 gridlines in many cases, and depending on where your data values fall, 5 gridlines may not work out to give you integer tick values.

The better thing to do is to turn on the variable number of gridlines feature by specifying:

gridlines: { count: -1}

Then it tries hard to give you nice round tick values.

You can also specify exactly what tick values you want by using the 'ticks' option.

gridlines: { ticks: [ -4, -2, 0, 2, 4 ] }

Finally, the official documentation: Customizing Axes: Number Formats

Upvotes: 1

Related Questions