Chartjs-How can I update multiple data variables of chart js label

0👍

You need to update all datasets, not only the first one you have.

setInterval(function() {
  //code goes here that will be run every 5 seconds.    

  lion.data.datasets[0].data = [getRandomInt(100), getRandomInt(100), getRandomInt(100), getRandomInt(100), getRandomInt(100), getRandomInt(100), getRandomInt(100), getRandomInt(100), getRandomInt(100)];
  lion.data.datasets[1].data = [getRandomInt(100), getRandomInt(100), getRandomInt(100), getRandomInt(100), getRandomInt(100), getRandomInt(100), getRandomInt(100), getRandomInt(100), getRandomInt(100)];
  //finally update chart var:
  lion.update();

}, 2000);

Or instead of hardcoding you can loop over them

setInterval(function() {
  //code goes here that will be run every 5 seconds.    

  lion.data.datasets.forEach(dataset => dataset.data = [getRandomInt(100), getRandomInt(100), getRandomInt(100), getRandomInt(100), getRandomInt(100), getRandomInt(100), getRandomInt(100), getRandomInt(100), getRandomInt(100)]);
  //finally update chart var:
  lion.update();

}, 2000);

Leave a comment