简体   繁体   English

Google图表Y轴步进

[英]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 . 我正在使用Google数据可视化API进行一个项目,并且试图显示一个图表,说明上周用户的访问次数。 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 . 问题在于此数字始终是整数且大于或等于0,但在我的图表上Y轴显示十进制数字。 how can I configure the options array to get only integers ? 如何配置options数组以仅获取整数?

在此处输入图片说明

From How to show only integers (no decimals) in chart API x/y-axis labels , user asgallant suggests this: 如何在图表API x / y轴标签中仅显示整数(无小数)开始 ,用户天真地建议:

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. Google Charts API假设在许多情况下需要5条网格线,并且根据数据值的下降位置,可能无法计算出5条网格线来为您提供整数刻度线值。

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. 您还可以使用“ ticks”选项确切指定所需的报价值。

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

Finally, the official documentation: Customizing Axes: Number Formats 最后是官方文档: 自定义轴:数字格式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM