UPDATE

Encode into JSON, result now looks like :
{"date":"2017-10-30","ph":"6"},{"date":"2017-10-29","ph":"7"},{"date":"2017-10-28","ph":"9"},{"date":"2017-10-27","ph":"8"},{"date":"2017-10-27","ph":"5"},

<?php

$db = pg_connect("host=localhost port=5432 dbname=postgres user=postgres");


$result = pg_query($db,"SELECT * FROM kv ORDER by date DESC LIMIT 5");
while ($row = pg_fetch_object($result)) {
 echo json_encode($row),',';
}
pg_close($db);
?>

In html added add.row
<html>
<head>
  <!--Load the AJAX API-->
  <title>title</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <script type="text/javascript" src="https://www.gstatic.com/
charts/loader.js"></script>
  <script type="text/javascript" src="//ajax.googleapis.com/
ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  <script type="text/javascript">

    google.charts.load('current', {packages: ['corechart', 'line']});
  google.charts.setOnLoadCallback(drawChart);
    
   function drawChart() {
    var jsonData = $.ajax({
        url: "getData2.php",
        dataType: "json"
        }).responseText;
        
     // Create our data table out of JSON data loaded from server.
     var data = new google.visualization.DataTable(jsonData);
    data.addColumn('date', 'date');
    data.addColumn('number', 'ph');
   data.addRows(JSON.parse(jsonData));

       var options = {
      max:9,
      min:6.5,
      width: 1000, height: 300,
      hAxis: {
        title:'date'
      },
      vAxis: {
          title: 'pH'
      },
      };


      var chart = new google.visualization.LineChart(document.getElementById
('chart_div'));
    chart.draw(data, options);
  }
  </script>
</head>

  <body>
  <!--Div that will hold the pie chart-->
  <div id="text">some text</div>
  <div id="chart_div"></div>
</body>
</html>

Still not working, I am not sure about this line
 data.addRows(JSON.parse(jsonData));   is this ok?


-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-visualization-api/d4ec70cc-ed0b-4d15-bcda-de812f3e7f30%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to