我试图将我的 x 轴值显示为系列的 highcharts 上的字符串,但得到 (0,1,2....) 这是 xaxis 数组索引位置。如何在 higcharts 上显示格式化为字符串的 xaxis 值?
这是我所拥有的
Highcharts.chart('container', {
title: {
text: 'Chart with time'
},
xAxis: {
type: 'datetime',
"labels": {
"formatter": function() {
console.log(this);
console.log(this.value.toString());
return this.value
}
},
},
series: [{
data: [
['Jan-1', 100],
['Jan-2', 120],
['Jan-3', 130]
]
}]
});
希望看到“Jan-1”、“Jan-2”作为 x 轴上的标签。这是下面 fiddle 的链接https://jsfiddle.net/dLfv2sbd/2/
最佳答案
删除标签
并使用type: 'category'
而不是type:'datetime'
:
Highcharts.chart('container', {
title: {
text: 'Chart with time'
},
xAxis: {
type: 'category',
},
series: [{
data: [
['Jan-1', 100],
['Jan-2', 120],
['Jan-3', 130]
]
}]
});
检查fiddle .
关于javascript - Highchart 在 x 轴上显示字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43683114/