i'm trying to dynamically populate a javascript object with data i have fetched from an api (pivotal tracker).
i have a javascript object called 'results' which looks like this:
[ {"state"=>"finished",
"range"=>"6 months",
"points"=>0,
"numberStories"=>0,
"points / story"=>"N/A"},
{"state"=>"finished",
"range"=>"9 months",
"points"=>0,
"numberStories"=>0,
"points / story"=>"N/A"},
{"state"=>"finished",
"range"=>"12 months",
"points"=>0,
"numberStories"=>0,
"points / story"=>"N/A"}]
and i'm trying to write the javascript which will dynamically populate the chartjs object so that i graph one line for each 'state' showing number of 'points' for each 'range.
the chartjs object (with dummy data) looks like this:
var data = {
labels : ["January","February","March","April","May","June","July"],
datasets : [
{
fillColor : "rgba(220,220,220,0.5)",
strokeColor : "rgba(220,220,220,1)",
pointColor : "rgba(220,220,220,1)",
pointStrokeColor : "#fff",
data : [65,59,90,81,56,55,40]
},
{
fillColor : "rgba(151,187,205,0.5)",
strokeColor : "rgba(151,187,205,1)",
pointColor : "rgba(151,187,205,1)",
pointStrokeColor : "#fff",
data : [28,48,40,19,96,27,100]
}
]
}
what i have tried so far is:
var data ={};
var data["labels"] = [];
for (var i = 0 ; i < results.length ; i++) {
data["labels"].push(results[i]["range"]);
}
its obvious that i haven't initialised the array inside data properly, but i can't quite figure out how this should be done. the same will apply to datasets, when i get there.... any pointers? thanks!