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
2 Answers
Reset to default 0This 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
版权声明:本文标题:javascript - highcharts: TypeError: Cannot read property '0' of undefined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745214377a2648076.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论