javascript - The same graph is repeated in my view and upon page refresh, the graph changes -
this loop in controller. trying create , display chart using angular js unable so. same graph repeated in view , upon page refresh, graph changes. want response "options" , "votes" json. mistake making?
for (var = 0; < response.response.options.length;i++) { labels.push(response.response.options[i].options); data.push(response.response.options[i].votes); $scope.labels = labels; $scope.data = [ data ];
this json. have multiple calls , multiple jsons called api.
{ "response": { "poll": { "id": "17", "story_id": "28346", "user_id": "32425", "question": "who's favorite actor?", "status": "1", "docs": "1473121969" }, "options": [ { "id": "59", "options": "1. hamza ali abbasi", "image_url": "31xjr2a6f838gwqkw68p.png", "doc": "1473121970", "votes": "3" }, { "id": "60", "options": "2. emmad irfani", "image_url": "w9yhbtlr39pzn9d9bijf.png", "doc": "1473121970" }, { "id": "61", "options": "3. shahbaz shigri", "image_url": "hxnbem90wtlo7eb8tuew.png", "doc": "1473122087" }, { "id": "62", "options": "4. fawad khan", "image_url": "f9q6ud83bjt8ateazzzs.png", "doc": "1473122111" } ] } }
i think know getting at, why isn't working, , may "data" array. here jsfiddle has working , displaying info want:
https://jsfiddle.net/jwb9acql/
if @ console output of object in original code, output was:
[labels: array[4], data: array[1]]
where "votes" in data reason put in subarray:
$scope.data = [ data ];
i removed array. see if helps. if not, need post graph code.
Comments
Post a Comment