0👍
There are multiple issues :
I am not sure you are reading your Object correctly, check the code for my implementation; The other issue is that Angular trows a $rootScope:infdig error due to how you are creating new arrays inside your functions, I fixed that as well, but you might need to modify it for your particular case.
This is one solution:
var chartData = [];
var chartLabels = [];
$scope.options = options;
$scope.makeChartLbl = function(data) {
chartData.length = 0;
data.forEach(function(datum) {
chartData.push(datum.name);
});
return chartData;
}
$scope.makeChartData = function(data) {
chartLabels.length = 0;
data.forEach(function(datum) {
chartLabels.push(datum.total_vote);
});
return chartLabels;
}
}]);
var options = [
{
"id": 1,
"pool_id": 1,
"name": "pool1 option1",
"total_vote": 1
},
{
"id": 2,
"pool_id": 1,
"name": "pool1 option2",
"total_vote": 0
}
];
Full code in codepen:
Result:
Source:stackexchange.com