Chartjs-Bar Chart cannot read data and label in laravel

0👍

I can see that your for loop looks malformed in terms of your use of the arr1 and arr2 arrays. Here are edits to your code

var labelGrafik = [];
for(var i=0; i<totunsur; i++){
    var ket = $('#unsur-'+i).val();
    labelGrafik.push(ket);
}

var dataGrafik = [];
for(var i=0; i<totunsur; i++){
    var value = $('#mean-'+i).val();
    dataGrafik.push(value);
}

var barchart = document.getElementById('flot-bar2-chart-ikm');
var chart = new Chart(barchart, {
type: 'bar',
data: {
    labels: labelGrafik,
    datasets: [{
    label: 'Data Penjualan',
    data: dataGrafik,
    backgroundColor: [
        'rgba(255, 99, 132, 0.2)',
        'rgba(255, 99, 132, 0.2)',
        'rgba(255, 99, 132, 0.2)',
        'rgba(255, 99, 132, 0.2)',
        'rgba(255, 99, 132, 0.2)',
        'rgba(255, 99, 132, 0.2)',
        'rgba(255, 99, 132, 0.2)',
        'rgba(255, 99, 132, 0.2)'
    ],
    borderColor: [
        'rgba(255,99,132,1)',
        'rgba(255,99,132,1)',
        'rgba(255,99,132,1)',
        'rgba(255,99,132,1)',
        'rgba(255,99,132,1)',
        'rgba(255,99,132,1)',
        'rgba(255,99,132,1)',
        'rgba(255,99,132,1)'
    ],
    borderWidth: 2
    }]
}
});

Leave a comment