Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

476
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!