HighStock图表给出未定义的错误

时间:2016-04-21 18:03:06

标签: javascript highstock

高图表试图让它使用多个系列时遇到问题,它会中途停止识别数据。

我不明白为什么它在调试器中开始正常,然后在我大约6或7时失败。

这是代码

function buildAndUpdateTempChart() {
      $.getJSON('server/getReadings.php', function (data) {
        $('#chartContainer').highcharts('StockChart', {
          chart:{
            events: {
              load: function(){
                          // set up the updating of the chart each second
                          //debugger;
                          var series = this.series[0];
                          //console.log('data is: ' + data);
                          for(var i = 0; i < data.length - 1; i++){
                              this.series[0].addPoint(data[i].temp, data[i].timestamp, true, true);
                              this.series[1].addPoint(data[i].aTemp, data[i].timestamp, true, true);
                          }


                          // setInterval(function () {
                          //   //get tick
                          //     var x = (new Date()).getTime(), // current time
                          //     y = Math.round(Math.random() * 100);
                          //     series.addPoint([x, y], true, true);

                          //   }, 1000);
                        }
                      }
                    },
                    rangeSelector: {
                      selected: 1
                    },

                    title: {
                      text: 'Temperature Sensor Readings'
                    },
                    yAxis: {
                      title: {
                        text: 'Degrees Celcius'
                      },
                      plotLines: [{
                        value: 10,
                        color: 'green',
                        dashStyle: 'shortdash',
                        width: 2,
                        label: {
                          text: 'Minimum tolerated.'
                        }
                      }, {
                        value: 100,
                        color: 'red',
                        dashStyle: 'shortdash',
                        width: 2,
                        label: {
                          text: 'Maximum tolerated.'
                        }
                      }]},
                      series: [{
                        name: 'Temp',
                        data: data,
                        tooltip: {
                          valueDecimals: 2
                        },
                        name: 'Ambient Temp',
                        data: data,
                        tooltip: {
                          valueDecimals: 2
                        },
                      }]
                    });
      })
    }
    $(document).ready(function(){
        buildAndUpdateTempChart(); //this is async so there rest of the app can continue to work
    });

0 个答案:

没有答案