我试图在这个API的折线图中显示x轴上的“日期”值和y轴上的“宣告”值。我得到了Highcharts Error #12,但数据没有显示在图表上。我已经像这样构造了series.data属性:[[date, announces],[date, announces], ...]。下面是我的代码:
dataChart: SequenceChartData[] = [];
bucketAnnouncements: Array<[Date, number]> = [];
ngOnInit(): void {
this.chartService.getSequenceChartData(this.data.peerAS, this.data.peerIPAddress, this.data.prefix)
.subscribe((data: SequenceChartData[]) => {
this.dataChart = data;
this.update = true;
this.show = true;
let firstDay = Infinity;
let lastDay = -Infinity;
for (const val of this.dataChart){
const date = moment.utc(val.date).unix();
if (firstDay > date) {
firstDay = date;
}
if (lastDay < date) {
lastDay = date;
}
}
for (let n = firstDay; n <= lastDay; n += 300) {
this.bucketAnnouncements[n] = [
new Date(n * 1000),
0
];
}
for (const val of this.dataChart) {
const date = val.date;
this.bucketAnnouncements[moment.utc(date).unix()][1] = val.announces;
}
this.chartOptions.series = [
{
name: 'ao',
type: 'line',
data: this.bucketAnnouncements,
color: '#009879',
}
];
});
}使用console.log似乎可以正确地分配数据:
1546300800: (2) [Tue Jan 01 2019 01:00:00 GMT+0100 (Central European Standard Time), 31]
1546301100: (2) [Tue Jan 01 2019 01:05:00 GMT+0100 (Central European Standard Time), 30]
1546301400: (2) [Tue Jan 01 2019 01:10:00 GMT+0100 (Central European Standard Time), 30]
1546301700: (2) [Tue Jan 01 2019 01:15:00 GMT+0100 (Central European Standard Time), 30]
1546302000: (2) [Tue Jan 01 2019 01:20:00 GMT+0100 (Central European Standard Time), 30]
1546302300: (2) [Tue Jan 01 2019 01:25:00 GMT+0100 (Central European Standard Time), 30]
1546302600: (2) [Tue Jan 01 2019 01:30:00 GMT+0100 (Central European Standard Time), 30]
...我还根据错误的建议将turboTreshold设置为更高的数字,但它仍然不起作用(仍然会给出警告):
plotOptions: {
series: {
turboThreshold: 500000,
...
}
}要更完整地理解我的代码,请参阅github repository (无法解决合并冲突)
发布于 2021-05-17 14:59:37
请注意,date格式。
例如,Tue Jan 01 2019 01:00:00 GMT+0100 (Central European Standard Time))不是Highcharts的数字。它只是一个字符串。
为了解决这个问题,请使用毫秒格式的时间戳。
在那里,您可能会找到一些将其从一种格式转换为另一种格式的方法。
MDN:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
https://stackoverflow.com/questions/67533555
复制相似问题