Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

365
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda