[Chartjs]-Web page doesn't display chart or any error

1👍

you’re appending your $data with AM and PM data so there are no 2 datasets instead there is only one dataset. Because of that $data[1] doesn’t exists. Declare another 2 arrays and insert there your data for AM and PM respectively, then insert $dataAM at $data[0]… Let the code speak for itself:

…PHP file

 $data = array();
 $dataAM = array();
 $dataPM = array();
    foreach ($result as $row) {
        $label[]  = $row["Technician"];
        $dataAM[] = $row["AM"];
        $dataPM[] .=$row['PM'];
    }
 $data[0] = $dataAM;
 $data[1] = $dataPM;

…HTML File

 data: {
      labels:<?=json_encode($label);?>,
      datasets: [{
          label: 'Fixed AM',
          data:<?=json_encode(array_values($data[0]));?>,
          backgroundColor: 'rgba(54, 162, 235, 0.2)',
          borderColor: 'rgba(54, 162, 235, 1)',
          borderWidth: 1
      },
      {
          label: 'Fixed PM',
          data:<?=json_encode(array_values($data[1]));?>,
          backgroundColor: 'rgba(255, 99, 132, 0.2)',
          borderColor: 'rgba(255,99,132,1)',
          borderWidth: 1
      }
    ]
  },

0👍

Typo error, changed this:

json_encode(array_values($data[0]))

to this:

json_encode(array_values($data))

Leave a comment