2

Example

Try it on Plunker

I'm trying to put together the graphics with dynamic data, because I get the webservice and looks like this:

var avaliacoes_descTipo = [];
var avaliacoes_quantidade = [];

angular.forEach(data, function(value, key) { 
                this.push(key + ': ' + value);
                avaliacoes_descTipo[key] = value.descTipo;
                avaliacoes_quantidade[key] = value.quantidade;
            }, log_avaliacoes);



And I no fixed place for example<br>
  **{w: [
                     {V: avaliacoes_descTipo [1]},
                     {V: avaliacoes_quantidade [1]}
                 ]}<br>
                 {w: [
                     {V: avaliacoes_descTipo [2]},
                     {V: avaliacoes_quantidade [2]}
                 ]}
]};**

Need your help to put dynamic, with foreach do not know any way to work will help me a lot, thank you!

1 Answer 1

1

Try to do this way:

app.controller('MainCtrl', function($scope) {
   var avaliacoes_descTipo = ["1", "12", "13"];
   var avaliacoes_quantidade = [1,2,3];
   var val = [];
   var i;
   var val1 = [];
$scope.avaliacoes = {};

for (i = 0; i < avaliacoes_descTipo.length; i++) {
  val = {c: [
    {v: avaliacoes_descTipo[i]},
    {v: avaliacoes_quantidade[i]}
  ]};

  val1.push(val);
}

$scope.avaliacoes.type = "PieChart";

$scope.onions = [
  {v: avaliacoes_descTipo[0]},
  {v: avaliacoes_quantidade[0]}
];

$scope.avaliacoes.data = {"cols": [
  {id: "t", label: "Topping", type: "string"},
  {id: "s", label: "Slices", type: "number"}
], "rows":
  val1

};

$scope.avaliacoes.options = {
  'title': '',
  'legend' : {'position': 'bottom'}
};

});
Sign up to request clarification or add additional context in comments.

Comments

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.