0

I am trying chart using angular-chart.js. While going through this documentation: Link For angular-chart pie chart, I have found out that, they have given $scope.data for values and $scope.labels for labels. But I have data like this.

$scope.pied = [{
       "Prospective":"4",
        "CallBacks"
:"0",
        "FollowUp"
: "4",
        "NotInterested"
:"1",
         "Closed"
: "0"
        }];

How to implement this data in angular-chart?

Om Bala
  • 169
  • 3
  • 18

1 Answers1

2

You can use angular.forEach to loop through the received data and generate the required structure e.g.

$scope.data = [];
$scope.labels = [];
angular.forEach($scope.pied, function (object) {
    for (var key in object) {
        $scope.data.push(object[key]);
        $scope.labels.push(key);
    }
});
WispyCloud
  • 4,140
  • 1
  • 28
  • 31
  • Thanks jtblin I will try this and revert back – Om Bala Feb 27 '16 at 02:51
  • hi jtblin i have to use this forEach in this code? $scope.pied = [{ "Prospective":"4", "CallBacks":"0", "FollowUp": "4", "NotInterested":"1", "Closed": "0" }]; i need to put 4,0,4,1,0 in data and names in labels – Om Bala Feb 27 '16 at 04:30
  • Thanks for the forEach jtblin :) – Om Bala Feb 27 '16 at 05:46