Chartjs-Provide Chart.js with data via AJAX JSON not working?

1👍

The way you populate oacData doesn’t sound right. I would expect this:

var oacData = [];
$.each(ChartData, function(i, item) {
    oacData.push(
        {
            value: ChartData[i].totalTonne,
            color: "#F7464A",
            highlight: "#FF5A5E",
            label: ChartData[i].wasteType
        }
    );
});

0👍

Now oacData is objects within an array within an array.
That’s why Chart.js can’t parse your data.
Just omit the brackets like:

var oacData = $.each(ChartData, function(i, item) {
                {
                    value: ChartData[i].totalTonne;
                    color: "#F7464A";
                    highlight: "#FF5A5E";
                    label: ChartData[i].wasteType;
                }
            });

And you will have an array with objects.

Leave a comment