-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
123 lines (113 loc) · 4.2 KB
/
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
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
<html>
<head>
<title>Test charts</title>
<script src="http://code.jquery.com/jquery-2.1.4.min.js" type="text/javascript"></script>
<script src="http://d3js.org/d3.v3.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rickshaw/1.5.1/rickshaw.min.js" type="text/javascript"></script>
<!-- <script src="index.js" type="text/javascript"></script> -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/rickshaw/1.5.1/rickshaw.min.css" media="screen" rel="stylesheet" type="text/css">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" media="screen" rel="stylesheet" type="text/css">
<!-- <link href="index.css" media="screen" rel="stylesheet" type="text/css"> -->
<style>
.chart_container {
position: relative;
display: inline-block;
/*font-family: Arial, Helvetica, sans-serif;*/
/*margin-top: 20px;*/
}
.chart {
/*position: absolute;*/
display: inline-block;
left: 50px;
}
.y_axis {
position: absolute;
top: 0;
bottom: 0;
width: 50px;
}
.y_axis > svg {
padding-bottom: 20px;
}
.x_tick {
bottom: -20px !important;
}
.legend {
display: inline-block;
vertical-align: top;
margin: 0 0 0 10px;
}
</style>
<script type="text/javascript">
$(function() {
var influxdb = 'http://127.0.0.1:8086/query';
var testQuery = 'SELECT mean("usage") FROM "network" WHERE "userId" = '+"'9131071'"+" AND time > '2017-08-10T07:00:00Z' AND time < '2017-08-20T12:03:40Z' GROUP BY time(1h) fill(0)";
$.getJSON( influxdb, {
db: 'NetUsage',
q: testQuery
},
function( influxData ) {
console.log(influxData)
drawGraph(
$('#test_chart'),
transformData(influxData),
'stack'
);
}
);
function transformData(influxData) {
var palette = new Rickshaw.Color.Palette();
return influxData.results[0].series.map(function(s) {
return {
name: JSON.stringify(s.tags),
data: s.values.map(function(v) {
return { x: new Date(v[0]).getTime() / 1000, y: v[1] };
}),
color: palette.color()
};
});
}
function drawGraph($element, series, renderer) {
//$element.find('.y_axis').css('background-color: red;')
var graph = new Rickshaw.Graph({
element: $element.find('.chart').get(0),
width: 800,
height: 200,
renderer: renderer,
series: series
});
var xAxis = new Rickshaw.Graph.Axis.Time({
graph: graph
});
var yAxis = new Rickshaw.Graph.Axis.Y({
graph: graph,
orientation: 'left',
element: $element.find('.y_axis').get(0)
});
var legend = new Rickshaw.Graph.Legend({
element: $element.find('.legend').get(0),
graph: graph
});
//xAxis.render();
//yAxis.render();
graph.render();
}
});
</script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<div id="test_chart" style="white-space: nowrap;">
<div class="chart_container">
<div class="y_axis"></div>
<div class="chart"></div>
</div>
<div class="legend"></div>
</div>
</div>
</div>
</div>
</body>
</html>