Implementing AngularJS to fetch values in JSON format using $resource call. The model element I require is a Javascript array structured as:
[
[1328983200000, 40],
[1328983200000, 33],
[1328983200000, 25],
[1328983200000, 54],
[1328983200000, 26],
[1328983200000, 25]
];
This data will be utilized for Flot charts and is present in the following JSON format:
{
"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},
}
The crucial elements are within "dailyMarks". Although I can convert this to a Javascript array, my current Controller code isn't producing the desired outcome:
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;
};
Facing issues with the conversion process resulting in an empty arr[] within the model. Seeking assistance on rectifying this issue.