admin管理员组

文章数量:1415420

I'm trying to feed some data from a REST API into HighCharts but I'm getting an error: TypeError: Cannot read property 'series' of undefined.

This gets the data from the API:

$scope.myData = function(chart) {

  HighCharts.query({
  }, 
  function(data) {
    $scope.highcharts = data;
    chart.series[0].setData($scope.getChart(data));
  });

};

Here's the getChart function:

$scope.getChart = function(data) {
    var response = [];

      $scope.highcharts.id.forEach(function(element, index){
        response.push([
          moment(element).toDate().getTime(),
          $scope.highcharts.value[index]
        ]);
      });

    return response;
  }

Any ideas about what am I doing wrong?

Update: I've updated the question as I'm getting a new error. You can see the full code at /.

I'm trying to feed some data from a REST API into HighCharts but I'm getting an error: TypeError: Cannot read property 'series' of undefined.

This gets the data from the API:

$scope.myData = function(chart) {

  HighCharts.query({
  }, 
  function(data) {
    $scope.highcharts = data;
    chart.series[0].setData($scope.getChart(data));
  });

};

Here's the getChart function:

$scope.getChart = function(data) {
    var response = [];

      $scope.highcharts.id.forEach(function(element, index){
        response.push([
          moment(element).toDate().getTime(),
          $scope.highcharts.value[index]
        ]);
      });

    return response;
  }

Any ideas about what am I doing wrong?

Update: I've updated the question as I'm getting a new error. You can see the full code at https://jsfiddle/raq0eg6e/.

Share Improve this question edited Feb 10, 2016 at 19:00 brians69 asked Feb 10, 2016 at 18:30 brians69brians69 4853 gold badges12 silver badges26 bronze badges 4
  • means chart.series is undefined – epascarello Commented Feb 10, 2016 at 18:33
  • The error message is self explanatory. Debug your code and check where something is undefined. – emerson.marini Commented Feb 10, 2016 at 18:34
  • @epascarello How can I define it, then? - jsfiddle/raq0eg6e – brians69 Commented Feb 10, 2016 at 19:03
  • In $scope.myData(); you should pass chart reference. If after fixing that problem, you are still having problems or errors - could you provide a fixed code? or even better - working, live example? – Kacper Madej Commented Feb 11, 2016 at 12:40
Add a ment  | 

2 Answers 2

Reset to default 0

This Line throwing error

  chart.series[0]

Just define a variable as follow

var  chart =("#yourContainerId").highcharts();

Based on the error, it looks like chart.series is undefined. You can log its value before chart.series[0].setData($scope.getChart(data)); with console.log(chart.series) to see if that is indeed the case.

本文标签: javascripthighcharts TypeError Cannot read property 39039 of undefinedStack Overflow