Chartjs-Chart.js not show in my function (function used in ajax) jquery

0👍

The problem is you are creating the chart only one time when window load in order to update chart you need to create it again for doing that you should remove window.onload() after doin this your success function should look like this

    success: function (data) {

    var dt = $.parseJSON(data);

    $.each(dt,function (i,v) {
        var arrcat = [];       
        arrcat.push(v.category);       
        arrcat.push(v.ttl1, v.ttl2);
        arrt1.push(v.ttl1);
        arrt2.push(v.ttl2);
        arrcat.push(v.p);
        arrav.push(v.p);

        arrlabel.push(arrcat);             
    });

    var config = {
        type: 'line',
        data: {
            labels: arrlabel,
            datasets: [{
                label: 'My First dataset',
                fill: false,
                backgroundColor: window.chartColors.red,
                borderColor: window.chartColors.red,
                data: arrt1
            }, {
                label: 'My Second dataset',
                fill: false,
                backgroundColor: window.chartColors.blue,
                borderColor: window.chartColors.blue,
                data: arrt2,
            }]
        },
        options: {
            responsive: true,
            title: {
                display: true,
                text: 'Chart with Multiline Labels'
            },
        }
    };

        var ctx = document.getElementById('canvas').getContext('2d');
        window.myLine = new Chart(ctx, config);

}

Let me know if you need more help

Leave a comment