Highcharts.js 如何将当前时间标签放在 xAxis 的末尾

Highcharts.js How to put current time label in the end of xAxis

本文关键字:xAxis 标签 时间 js Highcharts      更新时间:2023-09-26

我有一个日期格式为xAxis的图表。例如今天是 11 月 5 日。点间隔为 1 天。点开始 - 11 月 3 日。

将有"11 月 3 日"、"11 月 4 日"和"11 月 5 日"积分。但最后一点不应该是一天,而是当前时间。

像这样:"11 月 3 日"、"11 月 4 日"、"今天 16:30"

怎么办?

使用格式化程序,您可以在其中确定标签是否是最后一个。请参阅:http://jsfiddle.net/3bQne/664/

var chart = new Highcharts.Chart({
    chart: {
        renderTo: 'container'
    },
    xAxis: {
        type:'datetime',
        tickInterval: 24 * 3600 * 1000,
        labels: {
            overflow: 'justify',
            formatter: function (){
                if(this.isLast){
                    return 'today ' + Highcharts.dateFormat('%H:%M', (new Date().getTime()));    
                } else {
                    return Highcharts.dateFormat('%e of %b', this.value);
                }
            }
        }
    },
    series: [{
        pointStart: Date.UTC(2013, 10, 3),
        pointInterval: 24 * 3600 * 1000,
        data: [29.9, 71.5, 106.4]        
    }]
});