Chartjs-How do i have to implement my code to get correct json?

0👍

You’ll have to create an array of your data, then use json_encode

So an array like this :

$data = [
      'data' => ['labels' => $labels],
      'datasets' => $datasets
];
echo json_encode($data);

For $labels and $datasets : it’s also array that you can construct with your query results.
Your json will be like this : {'labels':..., 'datasets': ...}

Leave a comment