Annotation Chart, MySQL

35 views
Skip to first unread message

Michal Fröhr

unread,
Feb 4, 2021, 11:52:40 AM2/4/21
to Google Visualization API
Hey all,
maybe you can help me...
I have data in my database, MySQL.
1. column TIMESTAMP in format 2021-02-02 00:00:00
2. colum VALUE (float)

I want to use Annotation Chart but I do not know how to load data from table to chart. Here is my code:

<?php
 $con = mysqli_connect('server','user','pass','db');
?>

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

      function drawChart() {
        var data = new google.visualization.DataTable();
        data.addColumn('date', 'Date');
        data.addColumn('number', 'mm');
        data.addRows([
         

here how to put data from my db? I am laso not sure about timestamp format...
I tried this but no success:
<?php 
  $query = "SELECT * from SAVE_DATA";
  $exec = mysqli_query($con,$query);
  while($row = mysqli_fetch_array($exec)){
  echo "['".$row['Time']."',".$row['Value1']."],";
 }
?> 
         
         
        ]);
        
        

        var chart = new google.visualization.AnnotationChart(document.getElementById('chart_div'));

        var options = {
          displayAnnotations: true
        };

        chart.draw(data, options);
      }
    </script>
  </head>

  <body>
    <div id='chart_div' style='width: 100%; height: 600px;'></div>
  </body>
</html>


Thanks all for help.
MF

Reply all
Reply to author
Forward
0 new messages