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

147
Views
Updating chart.js with ajax

i'm trying to auto-update my chart js graph trough ajax , but my if statement always return the wrong awnser on the first iter , any idea why ? thank again. , tell me if you need anything more.

setInterval(addData, 10000);
//setting the loop with time interval
function addData() {
  $.ajax({
    url: 'get',
    url: "/hello-world/",
    success: function(response) {

      let labels = String(response.labels);
      let datas = response.datas;

      console.log('check', String(label.slice(-1)));
      console.log('in', labels);
      myChart.data.labels.slice(-2)[1]);


      if (labels == String(label.slice(-1))) {
        console.log('same content');
      } else {
        console.log('updating content', labels, 'to', String(label.slice(-1)));

        myChart.data.datasets[0].data.push(datas);
        myChart.data.labels.push(labels);
        myChart.update();
        console.log('revisu', myChart.data.labels.slice(-2)[0], ' : ', myChart.data.labels.slice(-2)[1]);
        if (myChart.data.labels.slice(-2)[0] == myChart.data.labels.slice(-2)[1]) {
          console.log("something's wrong");

          myChart.data.labels.pop();
          myChart.data.datasets[0].data.pop();
          myChart.update();
        } else {

        };
        myChart.update();
      }
    }
  });


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