





<?php 


 
  $query = "select date , SUM(total)  FROM orders GROUP BY date ORDER BY date desc LIMIT 3";
  $res = $conn->query($query);

  

  foreach($res as $data)
  {

    $month[] =  $data['date'];
    $amount[] = $data['SUM(total)'];
  }

?>


<div style="width: 20%;">
  <canvas id="myChart"></canvas>
</div>
 
<script>
  // === include 'setup' then 'config' above ===
  const labels = <?php echo json_encode($month) ?>;
  const data = {
    labels: labels,
    datasets: [{
      label: 'Sales by date',
      data: <?php echo json_encode($amount)?>,
      backgroundColor: [
      
        'rgb(54, 162, 235)'
     
      ],
     
      borderWidth: 1
    }]
  };

  const config = {
    type: 'bar',
    data: data,
    options: {
      
      scales: {
        y: {
          beginAtZero: true
        }
      }
    },
  };

  var myChart = new Chart(
    document.getElementById('myChart'),
    config
  );

</script>

