javascript - Highcharts 错误 15

标签 javascript 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
      ]
    ]
  }
]

这是我的尝试:

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 // 
});

如您所见,图表未正确显示: enter image description here 在控制台中我得到这个错误:

"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/

相关文章:

javascript - 代码组织 AngularJS 巨大的 Controller

Javascript 替换单引号

javascript - Highcharts 文本气泡

javascript - Highcharts 如何在设置数据处显示加载动画

javascript - 网络图表节点关系节点合并->highcharts

javascript - Webpack 插件创建监视文件夹

javascript - 通过 onsubmit 和 onclick 进行表单输入验证有什么区别?

javascript - 从 highcharts 图表中动态设置栏上的点击事件

javascript - 更改数据时,为什么每次按下按钮数据都会减少?

javascript - 将 json 数组从 PHP 返回到 jQuery AJAX