HighChart时间序列小时从下午4点开始

时间:2016-02-24 23:01:24

标签: datetime highcharts

我有一个小提琴:

http://jsfiddle.net/sawaira/944zsyy5/2/

$(function () {
console.log( [new Date(2010, 0, 1, 0, 0, 0), 1],
                [new Date(2010, 0, 1, 1, 0, 0), 2],
                [new Date(2010, 0, 1, 2, 0, 0), 3],
                [new Date(2010, 0, 1, 3, 0, 0), 4]);
    Highcharts.setOptions({                                            // This is for all plots, change Date axis to local timezone
                global : {
                    useUTC : false
                }
            });
    var chart = new Highcharts.Chart({

        chart: {
            renderTo: 'container',
            zoomType: 'xy'
        },

        xAxis: {
            type: 'datetime',
            labels: {
                    formatter: function () {
                        // Show hour and am/pm
                        console.log(this.value);
                        return Highcharts.dateFormat("%l %p", this.value);
                    },                    
                },           
        },
        series: [{
            data: [
                 [new Date(2010, 0, 1, 0, 0, 0), 1],
                [new Date(2010, 0, 1, 1, 0, 0), 2],
                [new Date(2010, 0, 1, 2, 0, 0), 3],
                [new Date(2010, 0, 1, 3, 0, 0), 4]               
             ]
        }]

    });
});

当使用HighChart选项在X轴上渲染时,我总是从下午4点开始得到结果。请注意,useUTC为false,我添加了一堆console.log()以查看时间值是否符合预期,并且它们是。

为什么我得到上面描述的结果?

1 个答案:

答案 0 :(得分:0)

似乎将值更改为.getTime()会使其正常工作。

相关问题