Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

368
Vistas
Chart.js : How to get a line created by sum of others line?

I'm actually using chart.js to make small chart like this :

screenshot

I have some integer values in y-axis and date in x-axis. Here you can see an example of my dataset : dataset

I want to add a new line, with as a value : the sum of the values ​​at each date. My datasets are dynamically generated. With the dataset I uploaded, the data of this line should be

0: Object { x: "2021-09-02", y: 20 }
​​1: Object { x: "2021-09-08", y: 13 }
​​​2: Object { x: "2021-09-08", y: 10 }

Can someone help me to get the loop which will sum that please ?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

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);

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda