0

I want to make an infinite loop to be able to update my chart with data posted below. I have three setTimeout()'s but how do I place them in a loop? Maybe some different solution is better?

setTimeout(function() {
    addData(myChart, [45, 50, 30, 34, 61, 53, 42], 0, );
}, 2000);

setTimeout(function() {
    addData(myChart, [50, 40, 20, 15, 89, 63, 5], 0, );
}, 7000);

setTimeout(function() {
    addData(myChart, [45, 50, 30, 34, 61, 53, 42], 0, );
}, 10000);
Ivan
  • 24,563
  • 6
  • 44
  • 76
Damien
  • 206
  • 1
  • 4
  • 14

1 Answers1

0

Use setInterval() instead, the function passed in will get executed every n ms (here 2000 for 2 seconds). And initialize myArray with first data point.

setInterval(function() {
  addData(myChart, myArray, 0, );
  myArray = updateData(); // this will populate your array with new data after every 2 seconds.
}, 2000);

function updateData() {
  return updatedArray; // array with new data points
}
Ivan
  • 24,563
  • 6
  • 44
  • 76
jANVI
  • 668
  • 3
  • 10