-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathtemp-humid-chart.html
68 lines (56 loc) · 2.14 KB
/
temp-humid-chart.html
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.1', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
function drawChart() {
var jsonData = $.ajax({
url: "getData.php",
dataType:"json",
async: false
}).responseText;
// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(jsonData);
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
// assumes you have timestamps in column 0, and two data series (columns 1 and 2)
var view = new google.visualization.DataView(data);
view.setColumns([{
type: 'datetime',
label: data.getColumnLabel(0),
calc: function (dt, row) {
var timestamp = dt.getValue(row, 0) * 1000; // convert to milliseconds
return new Date(timestamp);
}
}, 1, 2]);
var options = {
title: 'Temperature and Relative Humidity over Time',
width: 900,
height: 500,
vAxis: {title: "Temperature (C) and Humidity (%)"},
hAxis: {title: "Date and Time"},
// chartArea: {'width': '100%', 'height': '80%'},
}
chart.draw(view, options);
}
</script>
<script type="text/javascript" src="jQuery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
// First load the chart once
drawChart();
// Set interval to call the drawChart again
setInterval(drawChart, 60000);
});
</script>
</head>
<body>
<!--Div that will hold the line chart-->
<div id="chart_div"></div>
</body>
</html>