Chartjs-Chart JS not re rendering in Laravel Livewire

2👍

found the fix.

had to fire an emit event when the button is pressed along with it’s values contained under $data.

Then added this in my blade file

window.onload = function() {
Livewire.on('refreshCharts', ($data) => {
    var ctx = document.getElementById('pieChart').getContext('2d');
var myChart = new Chart(ctx, {
    type: 'doughnut',
    data: {
        datasets: [{
            data:  $data,
            backgroundColor: ['#7e22ce', '#fecaca'],
            label: 'Post',
        }, ],
        labels: ['Published', 'Reviewing'],
    },
    options: {
        responsive: true,
        cutoutPercentage: 50,
        legend: {
            display: false,
        },
    },
    });  
})

}

Leave a comment