javascript Highcharts y 轴千位分隔符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19810931/
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
Highcharts y axis thousands separator
提问by Nuno Nogueira
How to add a thousands separator to the Y Axis of Highcharts?
如何向 Highcharts 的 Y 轴添加千位分隔符?
This is what I have:
这就是我所拥有的:
yAxis: [{ // Primary yAxis
labels: {
format: '{point.y:,.0f} ',
style: {
color: cor1
}
},
// more code....
This is returning the error:
这是返回错误:
Uncaught TypeError: Cannot read property 'y' of undefined
未捕获的类型错误:无法读取未定义的属性“y”
回答by falsarella
In addition to what @jfrej suggested:
除了@jfrej 的建议:
- If you're directly formatting an axis, use
{value}
for bothyAxis
andxAxis
: - If you're formatting a point in a tooltip, you may want to use
{point.y}
and/or{point.x}
: - If you're directly formatting the point label, you may want to use
{x}
and/or{y}
:- Fiddle for
plotOptions.series.dataLabels
, formatting all points - Fiddle for
series.data.dataLabels
, formatting specific point
- Fiddle for
- 如果你直接格式化的轴,使用
{value}
两个yAxis
和xAxis
: - 如果您在工具提示中格式化一个点,您可能需要使用
{point.y}
和/或{point.x}
: - 如果您直接格式化点标签,您可能需要使用
{x}
和/或{y}
:
So, since you're formatting yAxis
, {value}
should work as expected:
因此,由于您正在格式化yAxis
,因此{value}
应该按预期工作:
yAxis: {
labels: {
format: '{value:,.0f} '
}
}
回答by futantan
If you find the above solution not working, try to add this:
如果您发现上述解决方案不起作用,请尝试添加以下内容:
Highcharts.setOptions({
lang: {
thousandsSep: ','
}
});