-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdash01.php
105 lines (81 loc) · 3.09 KB
/
dash01.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
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
<html lang="en">
<head>
<title>Dash 01</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<style>
</style>
</head>
<body>
<div class="mypanel"></div>
<script>
$.getJSON('http://dev2.irexnet.co.kr:8080/KISTI_Web/sensor/whole.do', function(data) {
myJson = data;
var text = '';
var date = [];
for(var i = 0;i<data.length;i++){
date[i] = data[i].TIME;
//date[i] = date[i].substr(0,10);
text += `${data[i].node_id} :
${date[i]} <br>
*****************************<br>`
}
var swapped;
do {
swapped = false;
for (var i=0; i < date.length-1; i++) {
if (date[i] > date[i+1]) {
var temp = data[i];
data[i] = data[i+1];
data[i+1] = temp;
var temp2 = date[i];
date[i] = date[i+1];
date[i+1] = temp2;
swapped = true;
}
}
} while (swapped);
//console.log(date);
var time = [], so2 = [], hum = [], pres = [];
for(var i = 0;i < data.length ; i++){
time[i] = data[i].TIME;
so2[i] = data[i].SO2;
hum[i] = data[i].HUM;
pres[i] = data[i].PRES
}
so2 = normalization(so2);
hum = normalization(hum);
pres = normalization(pres);
//alert(time);
var trace1 = {
x: time,
y: hum,
type: 'scatter'
};
var trace2 = {
x: time,
y: so2,
type: 'scatter'
};
var trace3 = {
x: time,
y: pres,
type: 'scatter'
};
var data = [trace1, trace2,trace3];
Plotly.newPlot('myDiv', data);
//$(".mypanel").html(text2);
});
function normalization(arr){
var max = Math.max.apply(Math, arr);
var min = Math.min.apply(Math, arr);
var len = arr.length;
for(var i = 0 ; i < len ; i++){
arr[i] = (arr[i] - min)/(max - min);
}
return arr;
}
</script>
<div id="myDiv"><!-- Plotly chart will be drawn inside this DIV --></div>
</body>
</html>