【发布时间】:2012-03-19 07:49:10
【问题描述】:
我有一个 highchart 柱形图,有时 y 轴数据显示为 [1000,2000,3000,4000],有时显示为 [1k, 2k, 3k, 4k]。
如何将其修复为单一类型的数据。
问候, 纳文·莱昂
【问题讨论】:
标签: javascript jquery graph charts highcharts
我有一个 highchart 柱形图,有时 y 轴数据显示为 [1000,2000,3000,4000],有时显示为 [1k, 2k, 3k, 4k]。
如何将其修复为单一类型的数据。
问候, 纳文·莱昂
【问题讨论】:
标签: javascript jquery graph charts highcharts
区别就在这里:
yAxis: {
labels: {
formatter: function() {
return this.value;
}
}
},
【讨论】:
formatter 函数中使用return Math.round(this.value/1000) + 'k';。
用于将 yaxis 值转换为 1k、2k、3k、4k 等:
yAxis:
{
labels:
{
formatter: function()
{
return Math.round(this.value/1000) + 'k';
}
}
},
【讨论】:
如果您在一张图表中使用数以百万计的数据,请检查一下。
yAxis: {
labels: {
formatter: function () {
if (this.value.toFixed(0) >= 1000000) {
return '$' + this.value.toFixed(0) / 1000000 + 'M';
} else {
return '$' + this.value.toFixed(0) / 1000 + 'K';
}
}
},
title: {
text: ''
}
},
【讨论】: