我正在尝试使用 highcharts 来表示这些数据:
[
{
"name": "c1",
"data": [
[
-52587360000000,
2
],
[
-52590038400000,
1
],
[
-52611724800000,
1
],
[
-52622611200000,
1
],
[
-52655184000000,
1
],
[
-52663392000000,
2
],
[
-52855545600000,
2
]
]
},
{
"name": "c2",
"data": [
[
-52587360000000,
2
],
[
-52590038400000,
1
],
[
-52611724800000,
1
],
[
-52622611200000,
1
],
[
-52655184000000,
1
],
[
-52663392000000,
2
],
[
-52855545600000,
2
]
]
},
{
"name": "c3",
"data": [
[
-52587360000000,
2
],
[
-52590038400000,
1
],
[
-52611724800000,
1
],
[
-52622611200000,
1
],
[
-52655184000000,
1
],
[
-52663392000000,
2
],
[
-52855545600000,
2
]
]
}
]
这是我的尝试:
container.highcharts({
title: {
text:"Name"
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {
month: '%e. %b',
year: '%b'
}
},
yAxis: {
title: {
text: 'Occurrence'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
valueSuffix: 'Occurrence'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
},
series: response //
});
如您所见,图表未正确显示: 在控制台中我得到这个错误:
"Highcharts error #15: www.highcharts.com/errors/15"
我的错误是什么?
最佳答案
正如 link in the error message 会告诉你的那样:
Highcharts expects data to be sorted
This happens when you are trying to create a line series or a stock chart where the data is not sorted in ascending X order. For performance reasons, Highcharts does not sort the data, instead it is required that the implementer pre-sorts the data.
在您的情况下,第一个系列中的 x 值是:
-52587360000000
-52590038400000
-52611724800000
-52622611200000
-52655184000000
-52663392000000
-52855545600000
只看前两个,很明显 -52587360000000
比 -52590038400000
更小(更负)。看来您实际上已经对它们进行了反向排序。也就是说,最大的数字在前,然后它们越来越小(更负)。
您必须更改系列中数据的顺序,以便首先是最小的数字,然后是值增加。
关于javascript - Highcharts 错误 15,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25082034/