-
Notifications
You must be signed in to change notification settings - Fork 10
/
cumulativeLineChart.html
executable file
·117 lines (103 loc) · 3.07 KB
/
cumulativeLineChart.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="assets/nv.d3.css" rel="stylesheet" type="text/css">
<script src="assets/zepto.min.js"></script>
<script src="assets/d3.min.js" charset="utf-8"></script>
<script src="assets/nv.d3.js"></script>
<style>
text {
font: 12px sans-serif;
}
svg {
display: block;
}
html, body, #chart1, svg {
margin: 0px;
padding: 0px;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="chart1">
<svg></svg>
</div>
<script>
// Wrapping in nv.addGraph allows for '0 timeout render', stores rendered charts in nv.graphs,
// and may do more in the future... it's NOT required
nv.addGraph(function() {
var chart = nv.models.cumulativeLineChart()
.useInteractiveGuideline(true)
.x(function(d) { return d[1] })
.y(function(d) { return d[0] })
.color(d3.scale.category10().range())
// .average(function(d) { return d.mean/1; })
.duration(300)
// .clipVoronoi(false);
chart.dispatch.on('renderEnd', function() {
console.log('render complete: cumulative line with guide line');
});
chart.xAxis.tickFormat(function(d) {
// console.log(d)
// return d3.time.format('%m/%d/%y')(new Date(d))
if(d == 200){
return "Req/Sec"
}
if(d == 100){
return "Requests/sec"
}
return d3.time.format('%m/%d/%y')(new Date(d))
});
chart.yAxis.tickFormat(d3.format(',.1%'));
d3.select('#chart1 svg')
.datum(cumulativeTestData())
.call(chart);
//TODO: Figure out a good way to do this automatically
nv.utils.windowResize(chart.update);
chart.dispatch.on('stateChange', function(e) { nv.log('New State:', JSON.stringify(e)); });
chart.state.dispatch.on('change', function(state){
nv.log('state', JSON.stringify(state));
});
return chart;
});
function cumulativeTestData() {
return [
{
key: "Express",
values: [
[ 0 , 00] ,
[ 4679.92 , 100],
[ 1288.37 , 200] ,
[ 588.37 , 300]
]
,
mean: 250
},
{
key: "Koa 1",
values: [
[ 0 , 00] ,
[ 4582.66 , 100] ,
[ 888.37 , 200] ,
[ 988.37 , 300]
]
,
mean: 70
},
{
key: "Koa 2",
mean: 185,
values: [
[ 0.00 , 00] ,
[ 720.00 , 100] ,
[ 2288.37 , 200],
[ 588.37 , 300]
]
}
];
}
</script>
</body></html>