【发布时间】:2020-05-13 21:54:31
【问题描述】:
我正在使用 Highcharts 显示来自 API 的数据。我想将我的 yAxis 标记为“数千”,并将数字显示为一位数。例如,我现在的图表标签是 2k, 4k, 6k, 8k, 10k 我想调整格式以仅显示 2,4,6,8,10
我目前正在使用formatter:function () { } 来返回我的2k,4k,6k...,因为它以前显示2000,4000,6000... 我在确定如何正确格式化我的数字以便以单个数字显示时遇到问题。
我的预期结果是左侧显示的 yAxis 标签显示 2,4,6,8,10
这是我的图表的jsfiddle。
这也是我的代码:
Highcharts.chart('container', {
chart: {
type: 'line'
},
title: {
text: 'Monthly Average Temperature'
},
subtitle: {
text: 'Source: WorldClimate.com'
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
yAxis: {
labels: {
formatter: function () {
return this.axis.defaultLabelFormatter.call(this);
}
},
title: {
text: 'Thousands'
}
},
plotOptions: {
line: {
dataLabels: {
enabled: false
},
enableMouseTracking: false
}
},
series: [{
name: 'Tokyo',
data: [3625, 4320, 4055, 4852, 5120, 6251, 7852, 8000, 9102, ]
}, {
name: 'London',
data: [2210, 3152, 3852, 4102, 4300, 4657, 6521, 7022, 7982]
}]
});
【问题讨论】:
标签: javascript highcharts