score:2

Accepted answer

using json_encode would mean that you are encoding the data in json format. this format,may not be acceptable by chartjs,as chartjs requires strings for labels, and numbers for data.

here is what you can do (only the required section of the code)

(please note):- copy and paste this in label tag in chartjs. you can do this exact same thing for data tag as well.

labels: [
        <?php
         for($i=0;$i<count($getdates);$i++){
            echo $getdates[$i];
            echo ','; 
         }
        ?>
         
        ],

also, make sure to send the data as an array from the backend, if you want to use this method.

as for the random color thing, i suggest you check out this github repository. you can search for other options for random colors as well.


Related Query

More Query from same tag