I am trying to create a dataset pattern like this from the rest service in my angular application.
Example:
$scope.chartSeries = [
{"name": "Google", "data": [100, 200, 400, 700, 300]},
{"name": "Yahoo", "data": [300, 100, null, 500, 200]},
{"name": "Facebook", "data": [500, 200, 200, 300, 500] },
{"name": "Microsoft", "data": [100, 100, 200, 300, 200] }
];
Right now this is my code to build a similar pattern ,
if (datai){
$rootScope.DashboardData =[];
$rootScope.DashboardData = datai;
var _fieldData = [];
widget.chartConfig.series = [];
widget.chartConfig.series =
$rootScope.DashboardData.map(function(elm) {
return {
name: elm[widget.seriesname],
data:_fieldData.push(elm[widget.dataname])
};
});
}
Problem is data field is not creating an array. This is the final output which the above code generates.
[{"name": "Google", "data": 1}];
$rootScope.DashboardData.map(function(elm) { _fieldData.push(elm[widget.dataname]) return { name: elm[widget.seriesname], data: _fieldData }; }); }