This is what I currently have.
[
[
{"label":"Year","type":"number"},
{"label":"Value","type":"number"},
],
{"2013" : 70},
{"2014" : 78},
{"2015" : 125},
{"2016" : 153}
]
this is what I am using to generate the above code.
var data = [
{"Year":2013,"Product":"A","Value":0},
{"Year":2013,"Product":"B","Value":20},
{"Year":2013,"Product":"A","Value":50},
{"Year":2014,"Product":"D","Value":55},
{"Year":2014,"Product":"M","Value":23},
{"Year":2015,"Product":"D","Value":73},
{"Year":2015,"Product":"A","Value":52},
{"Year":2016,"Product":"B","Value":65},
{"Year":2016,"Product":"A","Value":88}
];
var sum = data.reduce(function(res, product) {
if (!(product.Year in res)) {
res[product.Year] = product.Value;
} else {
res[product.Year] += product.Value;
}
return res;
}, {});
var result = [];
for (var year in sum) {
var tmp = {};
tmp[year] = sum[year];
result.push(tmp);
}
result.splice(0, 0, [{
label: 'Year',
type: 'number'
}, {
label: 'Value',
type: 'number'
}]);
and I want to organize them into [Year, Value]
pairs instead of objects, like this:
[["Year", "Value"], ["2013", 70], ["2014", 78], ["2015", 125], ["2016", 153]]
["Year","Value"] ...
and you want to convert to array only - as the output you seek is NOT an object at all[["Year","Value"], ["2013" , 70], ["2014", 78], ["2015", 125], ["2016",153]]