-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlpt_test.html
77 lines (70 loc) · 3.28 KB
/
lpt_test.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
<!DOCTYPE html>
<html>
<head>
<script src="jquery-3.4.1.min.js"></script>
<script src="jquery.jqplot.min.js"></script>
<link rel="stylesheet" type="text/css" href="jquery.jqplot.min.css" />
<script>
// function creates an http request to get MySQL data from local Node.js server
function getData() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var res = xmlhttp.responseText;
// parse JSON result
var pdata = JSON.parse(res);
// display the data
displayData(pdata);
}
};
xmlhttp.open("POST", "http://localhost:8080", true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
// parameter to differentiate request on server
xmlhttp.send("cmd=send");
}
// function displays data using jqPlot
function displayData(data) {
// counter to loop back to beginning of data
var counter = 0;
// 1 second interval to refresh data
var timer = setInterval(
function plot() {
if (counter < Object.keys(data).length) {
// actual jqPlot command with display options
var plt = $.jqplot('plot', [data[counter.toString()].dpts], {
axesDefaults: {
pad: 0
},
axes: {
yaxis: {
label: 'dBm',
min: -130.0,
max: -30.0,
}
},
grid: {
background: '#000000'
},
seriesDefaults: {
showMarker: false,
color: '#ffff00'
}
}).replot();
// display timestamp on graph
var txt = $('<div style="color:#00ff00; position:absolute; text-align:center; height:100%; top:220px; width:100%">Trace Time: ' + data[counter.toString()].time + '</div>').insertAfter('.jqplot-grid-canvas');
// update the counter after each blob
counter++;
} else {
counter = 0;
}
}, 1000);
}
</script>
</head>
<body>
<div>
<button id="btn" onclick="getData()">Start</button>
</div><br>
<div id="plot"></div>
</body>
</html>