I am using Chart Js and Angular Chart Directive. I need bar chart dynamically in my ng-repeat directive. https://jtblin.github.io/angular-chart.js/
According to their documentation i have to give two arrays
$scope.labels = ['2006', '2007', '2008', '2009', '2010', '2011', '2012'];
$scope.data = [
[65, 59, 80, 81, 56, 55, 40]
];
I have made two functions in my controller for generating graph label and data array.
$scope.makeChartLbl=function(data)
{
console.log(data);
var arr=[];
for(var d in data)
{
arr.push(d.name)
}
// console.log(arr);
return arr;
}
$scope.makeChartData=function(data)
{
console.log(data);
var arr=[];
for(var d in data)
{
arr.push(d.total_vote)
}
// console.log(arr);
return arr;
}
My options object in dataset like as
{
"options": [
{
"id": 1,
"pool_id": 1,
"name": "pool1 option1",
"total_vote": 1
},
{
"id": 2,
"pool_id": 1,
"name": "pool1 option2",
"total_vote": 0
},
...
...
]
}
In view with ng-repeat directive
<canvas id="bar" class="chart chart-bar"
chart-data="makeChartData(options)" chart-labels="makeChartLbl(options)">
</canvas>
but it is not generating chart. How can solve this issue?