Highcharts - 定时关机1小时(Highcharts - time off by 1 h

2019-10-18 15:34发布

我似乎无法找出为什么在x轴上的时间始终是一个小时之后。

我知道它得到的东西做这一行,但我不能工作了什么将其更改为。

 date = Date.parse(line[0] + ' UTC');

我目前的时区是伦敦。

我有这个文件:index.php文件

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Using Highcharts with PHP and MySQL</title>

<script type="text/javascript" src="js/jquery-1.7.1.min.js" ></script>
<script type="text/javascript" src="js/highcharts.js" ></script>
<script type="text/javascript" src="js/themes/gray.js"></script>

<script type="text/javascript">
    var chart;
                    $(document).ready(function() {
                            var options = {
                                    chart: {
                                            renderTo: 'container',
                                            defaultSeriesType: 'line',
                                            marginRight: 130,
                                            marginBottom: 25
                                    },
                                    title: {
                                  text: 'Temperature for the last hour',
                                            x: -20 //center
                                    },
                                    subtitle: {
                                            text: '',
                                            x: -20
                                    },
                                    xAxis: {
                                            type: 'datetime',
                                            tickInterval: 3600 * 1000, // one hour
                                            tickWidth: 0,
                                            gridLineWidth: 1,
                                            labels: {
                                                    align: 'center',
                                                    x: -3,
                                                    y: 20,
                                                    formatter: function() {
                                                            return Highcharts.dateFormat('%H:%M', this.value);
                                                    }
                                            }
                                    },
                                    yAxis: {
                                            title: {
                                                    text: 'Temperature'
                                            },
                                            plotLines: [{
                                                    value: 0,

                                                   width: 1,
                                                    color: '#808080'
                                            }]
                                    },
                                    tooltip: {
                                            formatter: function() {
                                            return Highcharts.dateFormat('%H:%M', this.x-(1000*3600)) +': <b>'+ this.y + '</b>';
                                            }
                                    },
                                    legend: {
                                            layout: 'vertical',
                                            align: 'right',
                                            verticalAlign: 'top',
                                            x: -10,
                                            y: 100,
                                            borderWidth: 0
                                    },
                                    series: [{
                                            name: 'Temperature'
                                    }]
                            }
                            // Load data asynchronously using jQuery. On success, add the data
                            // to the options and initiate the chart.
                            // This data is obtained by exporting a GA custom report to TSV.
                            // http://api.jquery.com/jQuery.get/
                            jQuery.get('data.php', null, function(tsv) {

                              var lines = [];
                                    traffic = [];
                                    try {
                                            // split the data return into lines and parse them
                                            tsv = tsv.split(/\n/g);
                                            jQuery.each(tsv, function(i, line) {
                                                    line = line.split(/\t/);
                                                    date = Date.parse(line[0]);
                                                    traffic.push([
                                                            date,
                                                            parseFloat(line[1].replace(',', ''), 10)
                                                    ]);
                                            });
                                    } catch (e) {  }
                                    options.series[0].data = traffic;
                                    chart = new Highcharts.Chart(options);
                            });
                    });
</script>
</head>
<body>

<div id="container" style="width: 100%; height: 400px; margin: 0 auto"></div>

</body>
</html>

我试着摆弄周围有类似的设置

date = Date.parse(line[0] + ' Europe/London');

date = Date.parse(line[0] + ' London');                    

我也试图把这个在PHP文件的顶部:

<?php date_default_timezone_set('Europe/London'); ?>  

data.php吐出:

2013-09-15 11:49:42 18.3 2013-09-15 11:52:42    18.4 2013-09-15 11:55:42    18.4 2013-09-15 11:58:42    18.4 2013-09-15 12:01:42    18.3 2013-09-15 12:04:42    18.5 2013-09-15 12:07:42    18.6 2013-09-15 12:10:43 18.6 2013-09-15 12:13:43   18.8 2013-09-15 12:16:43    19 2013-09-15 12:19:43  19.3 2013-09-15 12:22:43    19.4 2013-09-15 12:25:43    19.5 2013-09-15 12:28:43    19.6 2013-09-15 12:31:43    19.8 2013-09-15 12:34:45 20.1 2013-09-15 12:37:43   20.1 2013-09-15 12:40:43    20.2 2013-09-15 12:43:43    20.3 2013-09-15 12:46:43    20.3

当时间是正确的。

现在我已经加入:

    Highcharts.setOptions({
            global: { useUTC: false }
                    });

该刻度线是正确的,但对工具提示显示的时间仍然是一个小时之后。

更新:发现问题 - 我需要添加useUTC:false选项的建议,然后更改以下行,以及:

 return Highcharts.dateFormat('%H:%M', this.x-(1000*3600)) +': <b>'+ this.y + '</b>';

 return Highcharts.dateFormat('%H:%M', this) +': <b>'+ this.y + '</b>';

Answer 1:

伦敦在冬季和夏季期间,格林尼治标准时间BST使用。 参见: 这里

BST是相当于UTC + 1。 这是要知道这个原因的重要信息:你找回结果是UTC,不BST。 如果你想获取本地时间,则有必要设置useUTC全局选项:假的。 参见: 这里 。

本页面给出了如何正确设置你的全局选项的例子: 链接

从本质上讲,你需要添加如下:

global: {
  useUTC: false
}


Answer 2:

对我来说, useUTC: false是足够多的..也许你也可以尝试timezoneoffset的,但仍对我来说,与useUTC工作。

我完整的代码如下所示:

Highcharts.setOptions({
    global: {
        // timezoneOffset: +1,
        useUTC: false
    }
});

更多信息将在文件- http://api.highcharts.com/highcharts#global



文章来源: Highcharts - time off by 1 hour