I'm using AngularJS to make a $resource call to GET some values in JSON format. My requirement is that I've a model element that needs a Javascript array of the form:
[
[1328983200000, 40],
[1328983200000, 33],
[1328983200000, 25],
[1328983200000, 54],
[1328983200000, 26],
[1328983200000, 25]
];
to be displayed in Flot charts. This information is contained in the JSON as follows:
{
"marks1":15,
"marks2":20,
"dailyMarks":{
"2013-02-27T07:25:35.000+0000":40,
"2013-03-01T07:25:35.000+0000":33,
"2013-02-26T07:25:35.000+0000":25,
"2013-02-23T07:25:35.000+0000":54,
"2013-03-03T10:12:59.000+0000":26,
"2013-03-02T07:12:59.000+0000":25},
}
where "dailyMarks" contain the elements I need. I can convert "dailyMarks" to Javascript array, but it doesn't seem to work: (Below is my Controller code)
function MyController($scope, $resource) {
var User = $resource('/marks/fetch?from=:from&to=:to', {from: inStartDate, to: inEndDate}, {
getAll: {method: 'GET', isArray: false}
});
$scope.changeDate = function(fromDate, toDate) {
$scope.marks = User.getAll({from: fromDate, to: toDate});
};
var imarks = User.getAll();
$scope.marks = imarks;
var list = imarks.dailyMarks, arr = [];
for (var key in list) {
arr.push([+new Date(key), list[key]]);
}
$scope.myModel = arr;
};
What am I doing wrong? I get blank arr[] in the model. :( :( Kindly guide me.