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

477
Visualizações
How update reload chart.js

I could not find an answer in the bunch of posts so decided to ask for help. My javascript code is autorun after website has opened. Some calculation are done on server and got back json object. I use json data to make chart:

      var xdata1 = JSON.parse([xListaCzasA.val()]);
      var ydata1 = JSON.parse([yListaCisnienieA.val()]);
          
      var data1 = [
          {x:xdata1, y:ydata1},
          ];

      var ctx = document.getElementById("wykres1").getContext('2d');
      var myChart = new Chart(ctx, {
            type: 'line',
    data: {
            labels: xdata1,
 datasets: [{
            label: 'myTEST',
            data: ydata1,
            backgroundColor: 'rgba(255, 99, 132, 0.2)',
           }]
           },

Graph shows nice so works correct. After some click button I do a second calculation and again got a new json object. Calculations works becouse I see the results in the textboxes.However, my graph is not refreshing. I has created a piece of code below for update the graph. However, it not works:

 function dane() {
    
  myChart.config.data.labels = xdata1;
  myChart.config.data.datasets.data = ydata1;     
  
  myChart.update();
}

Any ideas? I has try many cofig of the code from websites but it not works.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The datasets are an array of of datasets. So you can just target data on datasets. You need to select the correct one first. Asuming you only have 1 dataset that can be done like so:

 function dane() { 
  myChart.config.data.labels = xdata1;
  myChart.config.data.datasets[0].data = ydata1;     
  
  myChart.update();
}

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