无法在Highcharts图中设置时区

时间:2018-12-11 18:12:34

标签: javascript highcharts timezone momentjs

我想在Highchart图表中设置时区“ America / Los_Angeles”,但我不想显示默认的客户端浏览器时区。为此,我在代码中添加了moment.js库。但是,当我运行此程序时,我遇到了错误。

Uncaught TypeError: n.tz is not a function
    at a.Time.getTimezoneOffset (highstock.js:97)
    at a.Time.timezoneOffset.set (highstock.js:95)
    at a.Time.getTimeTicks (highstock.js:99)
    at F.C.getTimeTicks (highstock.js:166)
    at F.<anonymous> (highstock.js:393)
    at F.a.(anonymous function) [as getTimeTicks] (https://url/highstock-6.0.5/highstock.js:19:376)
    at F.setTickPositions (highstock.js:139)
    at F.<anonymous> (highstock.js:404)
    at F.a.(anonymous function) [as setTickPositions] (https://url/highstock-6.0.5/highstock.js:19:376)
    at F.setTickInterval (highstock.js:138)

以下是我正在使用的Highchart图形代码

window.moment = moment;    

Highcharts.chart('chart1', {
                chart: {
                    type: 'area',
                    zoomType: 'x'
                },
          time: {
                    timezone: 'America/Los_Angeles'
                },
                title: {
                    text: 'graph'
                },
                subtitle: {
                    text: document.ontouchstart === undefined ?
                            'Click and drag in the plot area to zoom in' : 'Pinch the chart to zoom in'
                },
                xAxis: {
                    type: 'datetime'
                },
                yAxis: {
                    title: {
                        text: 'Attack Size'
                    }
                },
                tooltip: {
                    formatter: function () {
                         return  Highcharts.dateFormat('%b %e, %H:%M',new Date(this.x))+ '<br/> Attack <b>' + this.y + ' ]';
                   } 
                },
                credits: {
                    enabled: false
                  },
                legend: {
                    enabled: false
                },
                plotOptions: {
                    area: {
                    pointStart: 1940,
                    marker: {
                        enabled: false,
                        symbol: 'circle',
                        radius: 2,
                        states: {
                            hover: {
                                enabled: true
                                }
                            }
                        }
                    },
                    series:{
                        turboThreshold:4000
                    }
                },
                series: [{
                    name: 'Description',
                    data: data
                }]
            });

1 个答案:

答案 0 :(得分:0)

错误.tz is not a function意味着tz对象上的moment功能不可用,可能是因为尚未安装Moment-Timezone

您将需要导入the moment-timezone docs中所述的moment.jsmoment-timezone-with-data(或moment-timezone-with-data-2012-2020等)。