javascript Highcharts 错误 15
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25082034/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Highcharts error 15
提问by HymanTurky
i'm trying to represent these data using highcharts:
我正在尝试使用 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
]
]
}
]
This is what i try:
这就是我尝试的:
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 //
});
The chart isn't shown correctly as you can see:
and in console i get this error:
如您所见,图表未正确显示:
在控制台中,我收到此错误:
"Highcharts error #15: www.highcharts.com/errors/15"
what is my error?
我的错误是什么?
回答by Halvor Holsten Strand
As the link in the error messagewill tell you:
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.
Highcharts 希望对数据进行排序
当您尝试创建数据未按 X 升序排序的线系列或股票图表时,会发生这种情况。出于性能原因,Highcharts 不对数据进行排序,而是要求实现者对数据进行预排序。
In your case the x-values in your first series are:
在您的情况下,您的第一个系列中的 x 值是:
-52587360000000
-52590038400000
-52611724800000
-52622611200000
-52655184000000
-52663392000000
-52855545600000
Just looking at the first two it is clear that -52587360000000
is a smaller (more negative) number than -52590038400000
. It appears that you have in fact reverse-sorted them. That is, the largest number is first, then they get increasingly smaller (more negative).
只看前两个,很明显它-52587360000000
比 更小(更负)-52590038400000
。看来您实际上已经对它们进行了反向排序。也就是说,最大的数字是第一个,然后它们变得越来越小(更负)。
You will have to change the order of the data in the series so that the smallest number is first and then the values increase.
您必须更改系列中数据的顺序,以便最小的数字在前,然后值增加。
回答by suneelpervaiz
This issue occurs when you sort the date order by desc
当您按 desc 对日期顺序进行排序时会出现此问题
Note
笔记
- Do not sort the data order by date desc
- Instead sort the data order by date Asc
- 不要按日期 desc 对数据顺序进行排序
- 而是按日期 Asc 对数据顺序进行排序
Your issue will be resolved. Happy Coding
您的问题将得到解决。快乐编码
回答by u445908
in my case, the first element of the "data array" , is datetime-descend. this is incorrect for HiChart. e.g.
就我而言,“数据数组”的第一个元素是日期时间下降。这对 HiChart 来说是不正确的。例如
# this sort cause error 15 of highchart
[ 5, 'content...' ],
[ 4, 'content...' ],
[ 3, 'content...' ]
solution: re-order the array with the 'asend order' for the first element, e.g.
解决方案:使用第一个元素的“asend order”重新排序数组,例如
# this is working good
[ 3, 'content...' ],
[ 4, 'content...' ],
[ 5, 'content...' ]