Google 图表 Y 轴步长

Google charts Y-axis step

我正在使用 google 数据可视化 API 进行一个项目,我正在尝试显示一个图表来说明上周的用户访问次数。 问题是这个数字总是一个整数并且大于或等于 0 但在我的图表上 Y 轴显示小数。 如何配置选项数组以仅获取整数?

来自 How to show only integers (no decimals) in chart API x/y-axis labels,用户 asgallant 建议:

vAxis: {
    format: '#'
}

在同一个线程中,用户 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 ] }

最后,官方文档:Customizing Axes: Number Formats