Currently, I am utilizing Chart.js for visualizing some data and I require the chart to be updated after each iteration of a for loop. Unfortunately, the chart only updates at the conclusion of the for loop.
Despite my attempts with setInterval and setTimeout, I have not been able to achieve the desired outcome in my specific scenario.
function bubble() {
for (i = 0; i < num - 1; i++) {
for (j = 0; j < num - i - 1; j++) {
if (ar[j] > ar[j + 1]) {
var tmp = ar[j];
ar[j] = ar[j + 1];
ar[j + 1] = tmp;
myChart.data.datasets[0].data[j] = ar[j];
myChart.data.datasets[0].data[j + 1] = ar[j + 1];
myChart.update();
}
}
}
}
My goal is to update the chart after every iteration of my bubble sort algorithm, but unfortunately, it seems to only update once the outer loop has completed. Is there a solution to this issue?