I don't know php, but it appears this code:

while ($row = pg_fetch_object($result)) {
 echo json_encode($row),',';
}

is only going to output a sequence of rows, with ',' terminator.  Since the
addRows method needs an array of arrays, you need to wrap all those rows in
another array to get a single array of arrays: '[' ... ']'.

On Mon, Oct 23, 2017 at 6:06 AM, rocky <hrvojelovr...@gmail.com> wrote:

> 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/c
> harts/loader.js"></script>
>   <script type="text/javascript" src="//ajax.googleapis.com/aja
> x/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 google-visualization-api+unsubscr...@googlegroups.com.
> To post to this group, send email to google-visualization-api@
> googlegroups.com.
> 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
> <https://groups.google.com/d/msgid/google-visualization-api/d4ec70cc-ed0b-4d15-bcda-de812f3e7f30%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Daniel LaLiberte <https://plus.google.com/100631381223468223275?prsrc=2>
dlalibe...@google.com <dlalibe...@google.com>   5CC, Cambridge MA

-- 
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 google-visualization-api+unsubscr...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.
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/CAOtcSJOJRBqdHUEwYnzOZnfyct7Pqi_8f6D584J1u9E25-x%2BbQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to