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?

6
  • What have you tried so far? it seems you need to modify to data to make it work. Commented Feb 26, 2016 at 14:01
  • i am getting these values from service i can't change the json shaohao Lin bro Commented Feb 26, 2016 at 14:03
  • It's ok that you get it from service. You don't need to change the json, but you can modify the response json to some data structure to fit the requirement of the angualr-chart.js Commented Feb 26, 2016 at 14:12
  • Service response is updated how can I implement this Commented Feb 26, 2016 at 15:24
  • Can you make a plunker and update your code? Commented Feb 26, 2016 at 15:26

1 Answer 1

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);
    }
});
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks jtblin I will try this and revert back
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
Thanks for the forEach jtblin :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.