簡體   English   中英

如何顯示x軸Highcharts的第一個和最后一個標簽

[英]How to show first and last label of x axis Highcharts

我在其他答案上嘗試了一些解決方案,但無法獲得所需的結果..請幫助我。

我想在高圖中顯示第一個x軸標簽和最后一個。

我從這個答案嘗試{endOnTick:true,showLastLabel:true}( 強制Highcharts顯示最后一個x軸標簽 ),但是它在最后一個標簽上只顯示了一些數字。

這是我的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"]
}

您缺少2個類別來顯示2019-06

...
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","24th","the 25th"]
},

小提琴

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM