[Chartjs]-Chart.js : How to get a line created by sum of others line?

1👍

You can try this solutio

var array = [
  { x: "2021-09-02", y: 20 },
  { x: "2021-09-08", y: 13 },
  { x: "2021-09-08", y: 10 },
];

var result = [];
array.reduce(function(res, value) {
  if (!res[value.x]) {
    res[value.x] = { x: value.x, y: 0 };
    result.push(res[value.x])
  }
  res[value.x].y += value.y;
  return res;
}, {});

console.log(result);

Leave a comment