0

I'm trying to add the labels and datasets of my chart dynamically.

var LabelResults = [];
var DatasetResults = [];

var getObject = jQuery.getJSON("<?=base_url()?>admin/JSONDateTime/", function (data) {
    data.forEach(function (packet){
        LabelResults.push(packet.pickup_datetime);
        DatasetResults.push(packet.total);
    });
});


// chart snippet
data: {
        labels: LabelResults,
        type: 'line',
        defaultFontFamily: 'Montserrat',
        datasets: [{
            label: "Foods",
            data: DatasetResults,
            backgroundColor: 'transparent',
            borderColor: 'rgba(220,53,69,0.75)',
            borderWidth: 3,
            pointStyle: 'circle',
            pointRadius: 5,
            pointBorderColor: 'transparent',
            pointBackgroundColor: 'rgba(220,53,69,0.75)',
        }, {
            label: "Electronics",
            data: [500, 800],
            backgroundColor: 'transparent',
            borderColor: 'rgba(40,167,69,0.75)',
            borderWidth: 3,
            pointStyle: 'circle',
            pointRadius: 5,
            pointBorderColor: 'transparent',
            pointBackgroundColor: 'rgba(40,167,69,0.75)',
        }]
    }

When I assign the arrays onto labels and data respectively my line doesn't generate, however the other static line graph works perfectly. I've read other questions similar to mine, I'm sure I'm not generating 2d arrays. Do these properties don't recognize arrays at all or am I just doing something wrong? Thank you.

0 Answers0