-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdashboarding.html
218 lines (166 loc) · 6.3 KB
/
dashboarding.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="stylesheet" href="/NVD3/build/nv.d3.min.css" media="screen" charset="utf-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/css/bootstrap.min.css" media="screen" charset="utf-8">
<style>
.containerMe { width: 1000px; margin: 5% calc(50% - 500px); }
.row { border: solid purple; }
</style>
<body>
<div class="containerMe">
<div class="row">
<div class="span12">
<svg id="mainExample" style="height: 300px"></svg>
</div>
</div>
<div class="row">
<div class="span4"><svg id="exampleOne" style="height: 300px"></svg></div>
<div class="span4"><svg id="exampleTwo" style="height: 300px"></svg></div>
<div class="span4"><svg id="exampleThree" style="height: 300px"></svg></div>
</div>
</div>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="//d3js.org/d3.v3.min.js"></script>
<script src="/NVD3/build/nv.d3.min.js"></script>
<script type="text/javascript">
/* Inspired by Lee Byron's test data generator. */
function stream_layers(n, m, o) {
if (arguments.length < 3) o = 0;
function bump(a) {
var x = 1 / (.1 + Math.random()),
y = 2 * Math.random() - .5,
z = 10 / (.1 + Math.random());
for (var i = 0; i < m; i++) {
var w = (i / m - y) * z;
a[i] += x * Math.exp(-w * w);
}
}
return d3.range(n).map(function() {
var a = [], i;
for (i = 0; i < m; i++) a[i] = o + o * Math.random();
for (i = 0; i < 5; i++) bump(a);
return a.map(stream_index);
});
}
/* Another layer generator using gamma distributions. */
function stream_waves(n, m) {
return d3.range(n).map(function(i) {
return d3.range(m).map(function(j) {
var x = 20 * j / m - i / 3;
return 2 * x * Math.exp(-.5 * x);
}).map(stream_index);
});
}
function stream_index(d, i) {
return {x: i, y: Math.max(0, d)};
}
</script>
<script type="text/javascript">
(function() {
var mainExample, exampleOne, exampleTwo, exampleThree;
//var colors = d3.scale.category20().range();
var test_data = stream_layers(3,20 + Math.random()*50,.1).map(function(data, i) {
return {
key: 'Stream' + i
, values: data
//, color: colors[i]
};
});
// --------------------------- MAIN EXAMPLE ---------------------------------
nv.addGraph(function() {
var chart = nv.models.multiBarChart()
.margin({top: 50, bottom: 30, left: 40, right: 10});
chart.xAxis
.tickFormat(d3.format(',f'));
chart.yAxis
.tickFormat(d3.format(',.1f'));
d3.select('#mainExample')
.datum(test_data)
.transition().duration(500).call(chart);
nv.utils.windowResize(chart.update);
chart.legend.dispatch.on('legendClick.updateExamples', function() {
setTimeout(function() {
exampleOne.update();
exampleTwo.update();
exampleThree.update();
}, 100);
});
mainExample = chart;
return chart;
});
// --------------------------- EXAMPLE ONE ---------------------------------
nv.addGraph(function() {
var chart = nv.models.lineChart()
.showLegend(false)
.margin({top: 10, bottom: 30, left: 40, right: 10})
.useInteractiveGuideline(true)
;
chart.xAxis // chart sub-models (ie. xAxis, yAxis, etc) when accessed directly, return themselves, not the partent chart, so need to chain separately
.tickFormat(d3.format(',r'));
chart.yAxis
.tickFormat(d3.format(',.1f'));
d3.select('#exampleOne')
.datum(test_data)
.transition().duration(500)
.call(chart);
//TODO: Figure out a good way to do this automatically
nv.utils.windowResize(chart.update);
//nv.utils.windowResize(function() { d3.select('#chart1 svg').call(chart) });
exampleOne = chart;
return chart;
});
// --------------------------- EXAMPLE TWO ---------------------------------
nv.addGraph(function() {
var chart = nv.models.stackedAreaChart()
.margin({top: 10, bottom: 30, left: 40, right: 10})
.showControls(false)
.showLegend(false)
.useInteractiveGuideline(true)
.style('stream');
chart.yAxis
.showMaxMin(false)
.tickFormat(d3.format(',.1f'));
d3.select("#exampleTwo")
.datum(test_data)
.transition().duration(500).call(chart);
nv.utils.windowResize(chart.update);
chart.stacked.dispatch.on('areaClick.updateExamples', function(e) {
setTimeout(function() {
mainExample.update();
exampleOne.update();
//exampleTwo.update();
exampleThree.update();
}, 100);
})
exampleTwo = chart;
return chart;
});
// --------------------------- EXAMPLE THREE ---------------------------------
nv.addGraph(function() {
var chart = nv.models.stackedAreaChart()
.margin({top: 10, bottom: 30, left: 40, right: 10})
.showControls(false)
.showLegend(false)
.useInteractiveGuideline(true)
.style('stacked');
chart.yAxis
.tickFormat(d3.format(',.1f'));
d3.select("#exampleThree")
.datum(test_data)
.transition().duration(500).call(chart);
nv.utils.windowResize(chart.update);
chart.stacked.dispatch.on('areaClick.updateExamples', function(e) {
setTimeout(function() {
mainExample.update();
exampleOne.update();
exampleTwo.update();
//exampleThree.update();
}, 100);
})
exampleThree = chart;
return chart;
});
})();
</script>
</body>
</html>