[Chartjs]-Chartjs chart.update() function not rendering lines in foreground

1👍

Figured it out. I was using the example documentation for the update.chart() method which shows:

function addData(chart, data) {
    chart.data.datasets.forEach((dataset) => {
        dataset.data.push(data);
    });
    chart.update();
}

However, chartjs renders to the foreground the data that is declared first in the array. So, to make the data thats inserted into the chart using the chart.update() method, I replaced the push() method with an unshift() method. For example:

function addData(chart, data) {
    chart.data.datasets.forEach((dataset) => {
        dataset.data.unshift(data);
    });
    chart.update();
}

Leave a comment