Highstocks实时数据问题

时间:2016-11-24 20:11:11

标签: javascript json node.js highcharts live

问题是,我得到了Uncaught TypeError:无法设置属性' index' of high(...)at highcharts.js:281

这是请求数据!

var chart;      function requestData(){

        $.ajax({
               url: '/kwInst',
               success: function(point) {
               var series = chart.series[0],
               shift = series.data.length > 120; // shift if the series is
               // longer than 20
               console.log(point);
               // add the point
               var pointx=point.instKW;
               chart.series[0].addPoint(eval(pointx), true, shift);

               // call it again after one second

               setTimeout(requestData, 1000);
               },
               cache: false
               });
    }

这是主要功能..我真的不确定是什么推动了错误。尝试给出手动值并且它有效。

        $(document).ready(function() {
           $.getJSON('/kwStream', function (data) {
                   chart = new Highcharts.chart('container', {
                                     chart: {
                                     zoomType: 'x',
                                               events: {
                                               load: function() {
                                               chart = this; // `this` is the reference to the chart
                                               requestData();
                                               }
                                               }

                                     },
                                     title: {
                                     text: 'KW Usage'
                                     },
                                     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: 'Kilowatt'
                                     }
                                     },
                                     legend: {
                                     enabled: false
                                     },
                                     plotOptions: {
                                     area: {
                                     fillColor: {
                                      linearGradient: {
                                     x1: 0,
                                     y1: 0,
                                     x2: 0,
                                     y2: 1
                                     },
                                     stops: [
                                             [0, Highcharts.getOptions().colors[0]],
                                             [1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
                                             ]
                                     },
                                     marker: {
                                     radius: 2
                                     },
                                     lineWidth: 1,
                                     states: {
                                     hover: {
                                     lineWidth: 1
                                     }
                                     },
                                     threshold: null
                                     }
                                     },

                                     series: [{
                                              type: 'area',
                                              name: 'KW',
                                              data: data.KW
                                              }]
                                     });

                    console.log(JSON.stringify(data.KW));
                    });








          });

0 个答案:

没有答案