Chartjs-Chart.js how to inser values from json

0👍

Welcome to Stackoverflow. The issue is coming because you have initialised the chart first new Chart and you’re getting the updated values asynchronously. You can solve this problem by initialising chart once you have received the data.

e.g.

httpGetAsync(theCpuUrl, function(data, status) {
  var myData = JSON.parse(data);
   // storing time and values 
   let time=[], value=[];
   for (var i = 0; i < myData[0].length; i++) {
     time.push(myData[0][i].timestamp);
     value.push(myData[0][i].cpu);
   }
   // now you have data in time and value array ready
   --> here call the "new Chart" which you're calling above. <--
});

Leave a comment