score:2

Accepted answer

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)?>
            }
        ]
    },

Related Query

More Query from same tag