-
Notifications
You must be signed in to change notification settings - Fork 1
/
wind.js
executable file
·185 lines (176 loc) · 3.82 KB
/
wind.js
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
//Wind Speed chart
$(function () {
var seriesOptions = [],
yAxisOptions = [{
opposite: false,
title: {
text: 'mph'
},
floor: 0,
minorGridLineWidth: 0,
gridLineWidth: 0,
alternateGridColor: null,
plotBands: [{ // Light air
from: 0.6,
to: 3.3,
color: 'rgba(68, 170, 213, 0.1)',
label: {
text: 'Light air',
style: {
color: '#606060'
}
}
}, { // Light breeze
from: 3.3,
to: 7.4,
color: 'rgba(0, 0, 0, 0)',
label: {
text: 'Light breeze',
style: {
color: '#606060'
}
}
}, { // Gentle breeze
from: 7.4,
to: 12.3,
color: 'rgba(68, 170, 213, 0.1)',
label: {
text: 'Gentle breeze',
style: {
color: '#606060'
}
}
}, { // Moderate breeze
from: 12.3,
to: 17.8,
color: 'rgba(0, 0, 0, 0)',
label: {
text: 'Moderate breeze',
style: {
color: '#606060'
}
}
}, { // Fresh breeze
from: 17.8,
to: 24.5,
color: 'rgba(68, 170, 213, 0.1)',
label: {
text: 'Fresh breeze',
style: {
color: '#606060'
}
}
}, { // Strong breeze
from: 24.5,
to: 31.3,
color: 'rgba(0, 0, 0, 0)',
label: {
text: 'Strong breeze',
style: {
color: '#606060'
}
}
}, { // High wind
from: 31.3,
to: 33.5,
color: 'rgba(68, 170, 213, 0.1)',
label: {
text: 'High wind',
style: {
color: '#606060'
}
}
}]
},{
opposite: true,
title: {
text: 'Dir'
},
min: 0,
max: 360,
tickInterval: 90,
minorGridLineWidth: 0,
gridLineWidth: 0,
alternateGridColor: null,
}],
seriesCounter = 0,
mycharts = [
{sensor:'windspeed', name:'Wind Speed', type:'column', color: null, yAxisIndex: 0},
{sensor:'windgust', name:'Gust', type:'scatter', color:'red', yAxisIndex: 0},
{sensor:'winddir', name:'Dir', type:'scatter', color:'green', yAxisIndex: 1}
],
colors = Highcharts.getOptions().colors;
$.each(mycharts, function(i, mychart) {
$.getJSON('wsdata.php?sensor='+ mychart.sensor + '&stationid=' + STATIONID, function(data) {
seriesOptions[i] = {
type: mychart.type,
name: mychart.name,
color: mychart.color,
yAxis: mychart.yAxisIndex,
data: data
};
// As we're loading the data asynchronously, we don't know what order it will arrive. So
// we keep a counter and create the chart when all the data is loaded.
seriesCounter++;
if (seriesCounter == mycharts.length) {
createChart();
}
});
});
function createChart() {
Highcharts.setOptions({
global: {
useUTC: false
}
});
$('#windspeed').highcharts({
// chart: {
// type: 'column'
// },
title: {
text: 'Wind Speed (mph)'
},
legend: {
enabled: true,
align: 'right',
backgroundColor: 'white',
borderColor: 'black',
borderWidth: 2,
layout: 'vertical',
verticalAlign: 'top',
y: 100,
shadow: true
},
credits: {
enabled: false
},
exporting: {
enabled: false
},
xAxis: {
type: 'datetime',
labels: {
overflow: 'justify'
}
},
yAxis: yAxisOptions,
alignTicks: false,
tooltip: {
valueSuffix: ' mph'
},
plotOptions: {
column: {
marker: {
enabled: false
}
},
scatter: {
marker: {
radius: 1
}
}
},
series: seriesOptions
});
}
});