Javascript 如何在 HighChart 的 yAxis 上仅显示整数值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14238780/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to show only integer values on yAxis of HighChart?
提问by wergeld
We have a set of a data that contains counts of instances of events. These can only be integers. When we display data that has a high enough yValue the yAxis labels are integers. However, when we zoom in to ranges of data that have under y = 5 we see the tick markers show things like 0.5, 0.75, 1.5, etc. How can we force the yAxis labels to only show integer values?
我们有一组包含事件实例计数的数据。这些只能是整数。当我们显示具有足够高 yValue 的数据时,yAxis 标签是整数。但是,当我们放大到 y = 5 以下的数据范围时,我们会看到刻度标记显示 0.5、0.75、1.5 等。我们如何强制 yAxis 标签仅显示整数值?
Hereis an example bit of code with some data. As you zoom in to the lower value region of the chart you can see what I mean. This is the current yAxis setup:
这是带有一些数据的示例代码。当您放大图表的较低值区域时,您可以看到我的意思。这是当前的 yAxis 设置:
yAxis: {
labels: {
style: {
fontSize: '9px',
width: '175px'
}
},
title: {
text: ''
}
},
回答by Asad Saeeduddin
Set the allowDecimalsoption in the y axis to false in order to prevent non integer tick marks from being displayed:
将allowDecimalsy 轴中的选项设置为 false 以防止显示非整数刻度线:
yAxis: {
allowDecimals: false,
labels: {
style: {
fontSize: '9px',
width: '175px'
}
},
title: {
text: ''
}
}
Here is a demonstration: http://jsfiddle.net/sBC9K/
这是一个演示:http: //jsfiddle.net/sBC9K/

