Chartjs-ChartJS '_meta' error for AJAX Dataset

0👍

success is a callback function, meaning that it executes only after the ajax call is complete. This means that the variable barChartData is getting initialised before toll has any values. In fact, toll has not been initialised, since you’ve simply written var toll;.

  1. Initialize toll, and set it to null value.
  2. Get access to your chart.
  3. Add the toll data to your datasets and update the chart inside the success function.

    var toll = null;
    var chart = ... //Hopefully you have access to the instance of your chart? If not, please show the rest of your code.
    $.ajax({
        async   : false,
        type    : "GET",
        url : "barChartData.php",
        success : function(data) {
            toll = data;
            barChartData.datasets.push(toll);
            chart.update();
        }
    });
    
    var barChartData = {
        labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July','August','September','October','Novemeber','December'],
        datasets: []
    };
    

Leave a comment