Generate a Google Charts chart with Mysql database records

Asked

Viewed 49 times

0

Hello Friends Programmers I am in need of a help.

I’m trying to generate a chart with Google Chats of schedules per month, but in the database the saved dates are in the xx/xx/xxxx format. I wonder if anyone can help me so that I can put the months statically or dynamically if converting all the dates into months in full and the amount on the chart.

<html>
<head>
  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
  <script type="text/javascript">
    google.charts.load('current', {
      'packages': ['corechart']
    });
    google.charts.setOnLoadCallback(drawChart);

   function drawChart() {
      var data = google.visualization.arrayToDataTable([
        ['Meses', 'Agendamentos'],

    <?php
    include('connection.php');

    $query = mysqli_query($conn, "SELECT COUNT(agend_id) AS qtd FROM agendamento GROUP BY MONTH(agend_data)");

    $meses = [];
    while ($dados = mysqli_fetch_array($query)) {
        $mes = array_push($meses, "Janeiro", "Fevereiro", "Março", "Abril");
        $qtd = $dados['qtd'];
    ?>

      ['<?php print_r($mes); ?>', <?php echo $qtd; ?>],

    <?php } ?>
  ]);

  var options = {
    title: 'Company Performance',
    curveType: 'function',
    legend: {
      position: 'bottom'
    }
  };

  var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));

  chart.draw(data, options);
}


 </script>
</head>

<body>
  <div id="curve_chart" style="width: 900px; height: 500px"></div>
</body>

</html>

Estrutura do banco

Gráfico gerado

The graph above is that you can generate but only missing the months on the X of the chart.

I thank you in advance for any kind of help.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.