Does not show month in Line Chart using PHP MySQL

Viewed 46

Here I am draw the line chart to show the statistical details. Here I want to show the details as Monthly wise. Below is the code which I tried.

// line chart starts
$stmt3 = $conn->prepare("SELECT decease_name, DATE_FORMAT(date, '%M') as dates, count(*) Consultations from prescription WHERE decease_name !='Reconsultation Need' AND date BETWEEN ADDDATE(NOW(),-365) AND NOW()  group by decease_name , DATE_FORMAT(date, '%M')");

$stmt3->execute();
$result3 = $stmt3->get_result();
$chart_datass = '';
$label1 = '';
$label2 = '';
?>

    datasets: [
        
<?php

       while($row = mysqli_fetch_array($result3)){
      
            $chart_datass = "".$row['decease_name']." ";
            $label1 = "'".$row['Consultations']."', ";
            $label2 = "'".$row['dates']."' ";

?>
{
        labels: [<?php echo $label2; ?>],
        data: [<?php echo $label1; ?>],
        label: "<?php echo $chart_datass; ?>",
        borderColor: getRandomColor(),
        fill: false
      },

      <?php   } ?> 
        
    ]

In the database, the records shown as follows.

+---------------+------------+
| Decease NAME  |    Date    |
+---------------+------------+
| Diabetis      | 2021-09-15 |
| Dengue        | 2021-08-10 |
+---------------+------------+

But in the line chart it show as below.

enter image description here

I cant see the month name and it does not group as month. Could someone help me improve my code. Thanks in advance.

0 Answers
Related