Finally it's over.
php code
$result = pg_query($db,"SELECT kv.ph, kv.date FROM public.kv ORDER BY date
DESC LIMIT 5");
$rows = array();
//flag is not needed
$flag = true;
$table = array();
$table['cols'] = array(
array('label' => 'date', 'type' => 'date'),
array('label' => 'ph', 'type' => 'number'),
);
$rows = array();
while($r = pg_fetch_assoc($result)) {
// assumes dates are in the format "yyyy-MM-dd"
$dateString = $r['date'];
$dateArray = explode('-', $dateString);
$year = $dateArray[0];
$month = $dateArray[1] - 1; // subtract 1 to convert to javascript's
0-indexed months
$day = $dateArray[2];
$temp = array();
$temp[] = array('v' => "Date($year, $month, $day)");
$temp[] = array('v' => (integer) $r['ph']);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
echo $jsonTable = json_encode($table);
/* echo $jsonTable; */
?>
HTML
<!DOCTYPE HTML>
<head>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript"
src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript"
src="https://www.google.com/jsapi"></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",
async: false
}).responseText;
var data = new google.visualization.DataTable(jsonData);
//data.addColumn('number', 'ph');
//data.addColumn('date', 'date');
//var obj = JSON.parse(jsonData);
//data.addRows(obj);
var options = {
title:'pH vrijednost zadnjih 5 mjerenja',
width: 1000, height: 300,
hAxis: {
title:'datum'
},
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">graf</div>
<div id="chart_div"></div>
</body>
</html>
Result
<https://lh3.googleusercontent.com/-1QPKi-MtSzI/Wfrv2ZQqvjI/AAAAAAAABGI/jsG5DXVfWPUuILQzkVmMuW3xx6-D_tfrwCLcBGAs/s1600/Image%2B2.jpg>
Daniel thanks!
--
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/52ba5252-c10f-406c-a943-c80ef5870d33%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.