-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard.html
144 lines (123 loc) · 5.41 KB
/
dashboard.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<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" src="js/TsData.js"></script>
<script type="text/javascript">
// We instantiate one TsData object per channel here in the header
// We instantiate one TsData object per channel here in the header
var ts = new TsData();
// ts.setBaseUrl("");
// original ChannelId(57433);
ts.setChannelId(57781);
// ts.setApiKey("");
// Using this in the context of static data. set.Days is in the context of "days prior to now up to now" which will exclude all history.
ts.setResults(60*24);
//ts.setDays(30);
// ts.setStart("");
// ts.setEnd("");
// ts.setMin(0);
// ts.setMax(100);
// ts.setRound(2);
// ts.setTimescale(10);
// ts.setSum(10);
// ts.setAverage(50);
// ts.setMedian(100);
var dataTable;
var dash1, cont1, chart1, view1, options1;
function refreshData() {
console.log("RefreshData Called");
dataTable = ts.getDataTable(showCharts);
}
function showCharts() {
console.log("ShowCharts Called");
// Create a dashboard.
dash1 = new google.visualization.Dashboard(document.getElementById('dash1'));
// Create a range slider, passing some options
cont1 = new google.visualization.ControlWrapper({
'controlType': 'ChartRangeFilter',
'containerId': 'cont1',
'options': {
// Filter by the date axis.
'filterColumnIndex': 0,
'ui': {
'chartType': 'ComboChart',
'chartOptions': {
//'width': 500,
//'height': 300,
'chartArea': {'width': '90%'},
'hAxis': {'baselineColor': 'none'},
'vAxis': [{'title': 'Temperature', 'maxValue': 100, 'color': '#0A4C94'},{'title': 'Power', 'maxValue': '10','baselineColor': '#E08F14' }],
'series': { 0: {'targetAxisIndex': 0,'color':'#7c7c7c'}
}
},
// Display a single series that shows one of the series.
// Thus, this view has two columns: the date (axis) and the line series.
'chartView': {
'columns': [0,3],
// 'rows':(300,500),
},
// 1 day in milliseconds = 24 * 60 * 60 * 1000 = 86,400,000
'minRangeSize': 86400000/24
}
},
// Initial range: 2012-02-09 to 2012-03-20.
//'state': {'range': {'start': new Date(2012, 1, 9), 'end': new Date(2012, 2, 20)}}
});
dash1.bind(cont1, chart1);
// We can introduce views here to limit the number of columns
// displayed. Default is to show all columns.
//view1 = new google.visualization.DataView(dataTable);
//view1.setColumns([0, 1]);
dash1.draw(dataTable);
}
function initCharts() {
// Define a time line chart
chart1 = new google.visualization.ChartWrapper({
'chartType': 'ComboChart',
'containerId': 'chart1',
'options': {
'vAxis': [{'title': 'Temperature', 'maxValue': 100, 'color': '#0A4C94'},{'title': 'Power', 'maxValue': '10','baselineColor': '#E08F14' }],
'chartArea': {'width': '90%'},
//'width': 800,
//'height': 600,
'series': { 0: {'type': 'Area', 'targetAxisIndex': 1,'color':'#00923f'},
1: {'type': 'Area', 'targetAxisIndex': 0,'color':'#0061a5'},
2: {'type': 'Line', 'targetAxisIndex': 0,'color':'#eb9721'},
3: {'type': 'Line','targetAxisIndex': 0,'color':'#e93222'},
4: {'type': 'Line', 'targetAxisIndex': 0,'color':'#f0ce20'}}
},
});
refreshData();
}
// load the google chart visualization
google.load('visualization', '1', {packages:['corechart', 'controls']});
google.setOnLoadCallback(initCharts);
//This is irritating when you are trying to locate a precise point in a series - the refresh casues the chart to rescale
// setInterval('refreshData()', 60000);
</script>
</head>
<body>
<h1>Populating Google Charts with ThingSpeak Data</h1>
<p>Notice that these charts are live</p>
<h2>Area Chart</h2>
<div id="dash1" style="border: 1px solid #ccc">
<table class="columns">
<tr>
<td>
<div id="chart1" style="width: 915px; height: 300px;"></div>
</td>
</tr>
<tr>
<td>
<div id="cont1" style="width: 915px; height: 50px;"></div>
</td>
</tr>
</table>
</div>
</body>
</html>
<!--+
| vim: ts=4 et nowrap
+-->