0👍
✅
You have first to reduce the object by indexing result:
const data = dataset.reduce((accu, item) => {
if (accu[item.head] == null) accu[item.head] = { data: [], label: item.head };
accu[item.head].data.push(item.average);
return accu;
}, {});
then extract values from the result
const result = Object.values(data);
after that you may pad the result .data
field to get the right arity
result.forEach(line => {
while (line.data.length < 2)
line.data.unshift(0);
});
Source:stackexchange.com