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

155
Visualizações
React-chartjs-2 linechart is not updating after dataset changes

I have to render a chart js linechart with order data for each month from the json object returned from the API.

Sample JSON Object

[
 {
   yearCount:2021,
   ordersCount:23,
   monthCount:10,
   dayCount:20
 },
 {
   yearCount:2021,
   ordersCount:21,
   monthCount:10,
   dayCount:22
 },
 {
   yearCount:2021,
   ordersCount:21,
   monthCount:12,
   dayCount:26
 }
]

After getting the data from API I will loop through it and get the count of total orders for that month like this from the dashboard component.

    const [data , setData] = useState([]);

    for (let i = 0; i < 12; i++) {
        var count = 0;
        for (let j = 0; j < orderData.length; j++) {
            if (orderData[j].MonthNumber == i + 1) {
                count = count + orderData[j].TotalOrderCompleted;
            }
        }
        setData(...data , count);
    }

So that I will get the total count for each month that has orders and for other months 0. After that, from the main Dashboard component, I will pass this data as props to the My linechart component where I change the data dataset to the props data received. However, the data passed from the dashboard component is not getting updated. I tried to console.log the data array which is working fine.

about 4 years ago · Juan Pablo Isaza
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