Hi, I have a problem with retrieving the data from php Query in google
chart. I want to create line graph with "pH" values and "date" for last 5
records. I get graph with axis name but no more. Can someone show me next
step. I am absolute beginner. I know I need addRows but I don't know how to
do it. Thanks in advance. Already searched google groups but no luck.
In database date is date type, and pH is number.
Php
<?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_row($result)) {
echo "ph: $row[2] date: $row[3]";
echo "<br />\n";
}
?>
Result is:
ph: 6 date: 2017-10-30
ph: 7 date: 2017-10-29
ph: 9 date: 2017-10-28
ph: 5 date: 2017-10-27
ph: 6 date: 2017-10-26
And html
<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');
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>
--
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/bc83c7de-1375-4ba8-b9cf-55786920fc64%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.