gpt4 book ai didi

javascript - Google 图表 Y 轴步长

转载 作者:行者123 更新时间:2023-12-03 09:18:59 25 4
gpt4 key购买 nike

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

enter image description here

最佳答案

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

vAxis: {
format: '#'
}

在同一线程中,用户 Daniel LaLibertethis :

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

关于javascript - Google 图表 Y 轴步长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31893715/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com