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

474
Vistas
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 Respuestas
Responde la pregunta

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