Chartjs-Use chart.js on a page that was loaded by ajax

2👍

You DOM may not be ready as soon as your AJAX has completed. Try wrapping the Chart initialization in something that checks if the DOM is ready, like so

var interval = setInterval(function(){
    var canvas = document.getElementById("canvas");
    if (canvas) {
        var ctx = document.getElementById("canvas").getContext("2d");
        var chart = new Chart(ctx).Line(lineChartData, {
            responsive: true
        });
        clearInterval(interval)
    }
}, 100)

Also, you might want to ensure that your ajaxComplete function is actually getting called.

Leave a comment