我想在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
}]
});
答案 0 :(得分:0)
错误.tz is not a function
意味着tz
对象上的moment
功能不可用,可能是因为尚未安装Moment-Timezone。
您将需要导入the moment-timezone docs中所述的moment.js
和moment-timezone-with-data
(或moment-timezone-with-data-2012-2020
等)。