-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisualize.php
51 lines (45 loc) · 1.45 KB
/
visualize.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!-- Process received data, and display charts - Makhtar Diouf -->
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1', {'packages': ['corechart']});
google.setOnLoadCallback(drawChart);
<?php
$charts = ['hum', 'sound', 'light', 'temp'];
?>
function drawChart() {
var jsonData = $.ajax({
url: "read.php",
dataType: "json",
async: true
}).responseText;
// Create our data table out of JSON data loaded from server.
var data;
var options;
var chart;
<?php
$i = 0;
for (; $i < sizeof($charts); $i++) {
?>
data = new google.visualization.DataTable();
data.addColumn('datetime', 'Time');
<?php
echo "\t\t\t data.addColumn('number', '" . $charts[$i] . "');" .
"\n\t\t\t data.addRows([ ";
require_once 'read.php';
$obj = new ArduiData();
json_encode($obj->getData($charts[$i]));
?>
]);
options = {
title: '<?php echo $charts[$i]; ?> vs time',
curveType: 'function',
legend: {position: 'top'},
width: 500,
height: 300
};
// Instantiate and draw our chart
chart = new google.visualization.LineChart(document.getElementById('<?php echo $charts[$i]; ?>'));
chart.draw(data, options);
<?php } ?>
}
</script>