Highcharts在日期时间图表中显示错误的月份(下个月)

时间:2016-02-20 09:33:22

标签: datetime highcharts timezone timezone-offset

正如标题中所提到的,Highcharts会显示下个月而不是我想要显示的正确月份。

<script>

$(function () {
    Highcharts.setOptions({
        global: {
            //timezoneOffset: 3.30 * 60
        }
    });

    $('#container').highcharts({
        xAxis: {
            type: 'datetime',
            tickInterval: 3600 * 1000,
            min: Date.UTC(2016,02,20),
            max: Date.UTC(2016,02,21),
        },
        series: [{
            data: [
                [Date.UTC(2016, 02, 20,0,45), 1],
                [Date.UTC(2016, 02, 20,12,15), 3],
                [Date.UTC(2016, 02, 20,14,30), 6],
                [Date.UTC(2016, 02, 20,15,45), 9],
                [Date.UTC(2016, 02, 20,17,45), 5],
                ],
            pointStart: Date.UTC(2016, 02, 20),
            pointInterval: 3600 *1000
        }]
    });
});
</script>
<div id="container"></div>

因此,根据我提供的代码,我希望它在xAxis中显示2月,但它会跳转到3月。

如何解决此问题以显示我想要的月份?

Highcharts是否使用用户时区?如何显示固定时区并避免使用用户时区?

https://jsfiddle.net/v4kasmv1/

1 个答案:

答案 0 :(得分:5)

只需将2月min: Date.UTC(2016,01,20)的02到01编辑为00,1月为01,2月为02,3月为02:

$(function () {
    Highcharts.setOptions({
        global: {
            //timezoneOffset: 3.30 * 60
        }
    });

    $('#container').highcharts({
        xAxis: {
            type: 'datetime',
            tickInterval: 3600 * 1000,
            min: Date.UTC(2016,01,20),
            max: Date.UTC(2016,01,21),
        },
        series: [{
            data: [
                [Date.UTC(2016, 01, 20,0,45), 1],
                [Date.UTC(2016, 01, 20,12,15), 3],
                [Date.UTC(2016, 01, 20,14,30), 6],
                [Date.UTC(2016, 01, 20,15,45), 9],
                [Date.UTC(2016, 01, 20,17,45), 5],
                ],
            pointStart: Date.UTC(2016, 01, 20),
            pointInterval: 3600 *1000
        }]
    });
});