-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple.html
61 lines (53 loc) · 1.53 KB
/
simple.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
<html>
<head>
<script src="vendor/jquery-1.11.0.min.js"></script>
<script src="vendor/dygraph-combined.js"></script>
</head>
<body>
<div id="div_g" style="position: absolute; left: 0px; right: 0px; top: 0px; bottom: 0px;"></div>
<script>
function showGraph() {
$.ajax('bottom.txt',{
success: function(data) {
renderGraph(prepareData(data));
}
});
}
function prepareData(data) {
var rows = data.split('\n');
var matrix = [];
rows.forEach(function (row) {
matrix.push(row.split(' '));
});
var series = [];
var x = 0;
for (var i = 0; i < matrix[0].length; i++) {
var s = [x++];
for (var y = 0; y < matrix.length; y++) {
s.push(matrix[y][i]);
}
series.push(s);
}
return series;
}
function renderGraph(data) {
var labels = [];
var i = 0;
data[0].forEach(function(v) {
labels.push(i++)
})
var g = new Dygraph(
document.getElementById("div_g"),
data,
{
labels: labels,
animatedZooms: true
}
);
}
$(document).ready(function () {
showGraph();
});
</script>
</body>
</html>