gpt4 book ai didi

javascript - 如何显示 x 轴 Highcharts 的第一个和最后一个标签

转载 作者:行者123 更新时间:2023-12-02 23:29:56 25 4
gpt4 key购买 nike

我在其他答案上尝试了一些解决方案,但无法得到我想要的结果..请帮助我。

我想在 highcharts 中显示第一个 x 轴标签和最后一个 x 轴标签。

我尝试了这个答案( Force Highcharts to show last x-axis label )中的 {endOnTick: true, showLastLabel: true} 但它只显示最后一个数字..而不是实际的最后一个标签。

这是我的 x 轴选项

xAxis: {
type: 'Month',
// tickInterval is 5 this time
tickInterval: <?php echo number_format($num_results/5, 0);?>,
endOnTick: true, // it shows "25" at the end of the label. not "2019-06"
showLastLabel: true, // Default is true though..
labels: {
autoRotation: 0
},
//I get those categories from server
//so it could be different every time
//but this time I just write the result of it.
categories: ["2017-07","2017-08","2017-09","2017-10","2017-11","2017-12","2018-01","2018-02","2018-03","2018-04","2018-05","2018-06","2018-07","2018-08","2018-09","2018-10","2018-11","2018-12","2019-01","2019-02","2019-03","2019-04","2019-05","2019-06"]
}

预期的 x 轴标签是“2017-07 2017-12 2018-05 2018-10 2019-03 2019-06”

实际结果是“2017-07 2017-12 2018-05 2018-10 2019-03 25”

最佳答案

啊,我使用了tickPositioner并解决了它!

xAxis: {
type: 'Linear',
tickmarkPlacement: 'on',
tickPositioner: function() {
var positions = [],
ext = this.getExtremes(),
xMax = Math.round(ext.max),
xMin = Math.round(ext.min);

for (var i = xMin; i < xMax; i++) {
if (i % <?php echo number_format($num_results/3,0);?> == 0) {
positions.push(i);
}
}
positions.push(xMax);
return positions;
},
labels: {
autoRotation: 0,
},
categories: ["2017-07","2017-08","2017-09","2017-10","2017-11","2017-12","2018-01","2018-02","2018-03","2018-04","2018-05","2018-06","2018-07","2018-08","2018-09","2018-10","2018-11","2018-12","2019-01","2019-02","2019-03","2019-04","2019-05","2019-06"]
}

关于javascript - 如何显示 x 轴 Highcharts 的第一个和最后一个标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56558849/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com