-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
183 lines (170 loc) · 5.66 KB
/
index.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
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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
<title>farm</title>
<!-- Bootstrap -->
<link href="./css/bootstrap.min.css" rel="stylesheet">
<script src="echarts.min.js"></script>
<script src="jquery.js"></script>
</head>
<body>
<nav class="navbar navbar-inverse">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">智能农场</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="container-fluid">
<center>
<div class="row">
<div class="col-md-4" id="temperature" style="width: 400px;height:400px;"></div>
<div class="col-md-4" id="humidity" style="width: 400px;height:400px;"></div>
<div class="col-md-4" id="light" style="width: 400px;height:400px;"></div>
</div>
<div class="row">
<div class="col-md-4" >
<p class="text-center" id="temperatureText"></p>
</div>
<div class="col-md-4" >
<p class="text-center" id="humidityText"></p>
</div>
<div class="col-md-4" >
<p class="text-center" id="lightText"></p>
</div>
</div>
</div>
<script type="text/javascript">
// 基于准备好的dom,初始化echarts实例
var myChartTemperature = echarts.init(document.getElementById('temperature'));
var myChartHumidity = echarts.init(document.getElementById('humidity'));
var myChartLight = echarts.init(document.getElementById('light'));
// 显示标题,图例和空的坐标轴
myChartTemperature.setOption({
title: {
text: '温度异步加载'
},
tooltip: {},
legend: {
data:['温度']
},
xAxis: {
data: []
},
yAxis: {
min: 25,
max: 35
},
series: [{
smooth: true,
areaStyle: {},
name: '温度',
type: 'line',
data: [],
}]
});
myChartHumidity.setOption({
title: {
text: '湿度异步加载'
},
tooltip: {},
legend: {
data:['湿度']
},
xAxis: {
data: []
},
yAxis: {
min: 45,
max: 60
},
series: [{
smooth: true,
name: '湿度',
type: 'line',
data: []
}]
});
myChartLight.setOption({
title: {
text: '光强异步加载'
},
tooltip: {},
legend: {
data:['光强']
},
xAxis: {
data: []
},
yAxis: {
min: 320,
max: 380
},
series: [{
name: '光强',
type: 'line',
data: []
}]
});
var temperatures = [];
var humiditys = [];
var lights = [];
var date = [];
var now = new Date();
// 异步加载数据
function timer() {
now = [now.getHours(),now.getMinutes(),now.getSeconds()].join(':');
date.push(now);
$.get('thInfo.json').done(function (jsondata) {
temperatures.push(jsondata.temperature)
humiditys.push(jsondata.humidity)
lights.push(jsondata.light)
document.getElementById("temperatureText").innerHTML="当前温度:"+jsondata.temperature;
document.getElementById("humidityText").innerHTML="当前湿度:"+jsondata.humidity;
document.getElementById("lightText").innerHTML="当前光强:"+jsondata.light;
// 填入数据
myChartTemperature.setOption({
xAxis: {
data: date
},
series: [{
// 根据名字对应到相应的系列
name: '温度',
data: temperatures
}]
});
myChartHumidity.setOption({
xAxis: {
data: date
},
series: [{
// 根据名字对应到相应的系列
name: '湿度',
data: humiditys
}]
});
myChartLight.setOption({
xAxis: {
data: date
},
series: [{
// 根据名字对应到相应的系列
name: '光强',
data: lights
}]
});
});
now = new Date();
}
setInterval(timer,5000)
</script>
<script src="jquery.js"></script>
<script src="./js/bootstrap.min.js"></script>
</body>
</html>