Chartjs-Chart.js | Trouble refreshing line chart with "setInterval"

0👍

ended wrapping the above code in a function (drawChartRT). I then:

1) Call the function drawChartRT() to draw the LineChart.

2) Inside a setInterval remove and add the canvas and call the function drawChartRT().

    drawChartRT();
    setInterval(function () {
        $("canvas#chart_last2hours").remove();
        $("#chartdiv_rt").append('<canvas id="chart_last2hours" height="200"></canvas>');
        var div = document.getElementById("chart_last2hours");
        //console.log(div);
        drawChartRT();
    }, 10000);

Works like a charm!

Thanks. José

Leave a comment