-
Notifications
You must be signed in to change notification settings - Fork 0
/
foo.html
59 lines (52 loc) · 1.6 KB
/
foo.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
<html style="height: 100%">
<head>
<!-- Plotly.js -->
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
<div id="myDiv"><!-- Plotly chart will be drawn inside this DIV --></div>
<script>
function plotChart() {
var http = new XMLHttpRequest();
http.open("GET", "/getData", true);
http.setRequestHeader('Content-type', 'application/json');
http.onreadystatechange = function () {
if(http.readyState === XMLHttpRequest.DONE && http.status === 200 && http.responseText) {
var resp = JSON.parse(http.responseText);
// console.log(resp);
if (resp.length == 0)
{
document.getElementById('container').innerHTML = "<p><h1>NO DATA YET!</h1></p>"
}
else {
var xData = [];
var yData = [];
resp.forEach(function (point) {
var date = new Date(point[0]);
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
var hours = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();
xData.push(day + "/" + month + "/" + year + " " + hours + ":" + minutes + ":" + seconds);
yData.push(point[1]);
})
var data = [
{
x: xData,
y: yData,
type: 'scatter'
}
];
Plotly.newPlot('myDiv', data);
}
}
};
http.send();
setTimeout(function () {plotChart();}, 90000);
}
plotChart();
</script>
</body>
</html>