Chartjs-Accessing data in an associative array in CodeIgniter 3

2👍

Since you want your variables appear in Javascript you need to json_encode them. your $label and $data is still in PHP you can just echo it out into a json.

in your view you can do following

   data: {
        labels: <?= json_encode($label)?>,
        datasets: [
            {
                label: "Population (millions)",
                backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9","#c45850"],
                data: <?= json_encode($data)?>
            }
        ]
    },

Leave a comment