I'm attempting to use Angular-Chart in my AngularJS app.
From the documentation, I see that you can define Labels, Series and Data like this:
$scope.labels = ['2006', '2007', '2008', '2009', '2010', '2011', '2012'];
$scope.series = ['Series A', 'Series B'];
$scope.data = [
[65, 59, 80, 81, 56, 55, 40],
[28, 48, 40, 19, 86, 27, 90]
];
My problem is that in my case, the labels are key values from objects, and series and data are value and property from such objects.
For instance, given the following example:
Labels would be: ['324', '369', '391', '396', 'KE-22']
(Key from all objects in Cars)
Series would be: ['Trips','Total']
(Value from Cars)
And Data would be (Property from Cars):
[
['1','4','5','3','7'],
['00:00:08','00:00:13','00:00:24','00:00:03','00:00:01']
]
Is there some way I can create such arrays?
Right now I create the objects using LoDash, like so:
dataByMonth = _.mapValues(dataByMonth, function(month) {
var obj = {};
var carArray = [];
carArray = _.groupBy(month, 'car');
obj.Cars = _.groupBy(month, 'car');
obj.Drivers = _.groupBy(month, 'driver');
_.each(obj, function(groupsValue, groupKey) {
obj[groupKey] = _.mapValues(groupsValue, function(groupValue) {
return _.reduce(groupValue, function(sum, trip) {
sum['trips']++;
sum['duration']+= moment.utc(trip.duration, 'HH:mm:ss');
sum['total'] = moment.utc(sum.duration). format('HH:mm:ss')
//addDuration(sum.duration, car.duration);
return sum;
}, {trips: 0, duration: 0, total:0})
});
})
return obj;
});
$scope.statistics = dataByMonth;
Series
anddata
, as series-1 (Trips) will be showing the first array in Data and series-2 (Total) will be showing the second array in Data. I will update the question later with more diagrams to make it more clear anyway! – Eric Mitjans Nov 28 '14 at 10:27