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
<!DOCTYPE html>
<meta charset="utf-8">
<link href="../src/nv.d3.css" rel="stylesheet" type="text/css">
<link href="teststyle.css" rel="stylesheet" type='text/css'>
<body class='with-3d-shadow with-transitions'>
<h3>Multibar chart test cases - feel free to add more tests</h3>
<div class='navigation'>
<a href="../examples/multiBar.html">Multibar Stream example</a>
</div>
<div class='chart half' id="chart1">
Normal chart, with transition delay, and bar color set.
<svg></svg>
</div>
<div class='chart half' id="chart2">
Normal chart, no transitionDuration or delay, no bar color set.
<svg></svg>
</div>
<div class='chart half' id="chart3">
Chart with single series, no group spacing.
<svg></svg>
</div>
<div class='chart half' id="chart4">
Chart with 18 series, 7 data points per series.
<svg></svg>
</div>
<div class='chart third' id="chart5">
Chart with 1 data point
<svg></svg>
</div>
<div class='chart third' id="chart6">
Chart with 2 data points
<svg></svg>
</div>
<div class='chart third' id="chart7">
Chart with 0 data points
<svg></svg>
</div>
<script src="../lib/d3.v3.js"></script>
<script src="../nv.d3.js"></script>
<script src="../src/tooltip.js"></script>
<script src="../src/utils.js"></script>
<script src="../src/models/legend.js"></script>
<script src="../src/models/axis.js"></script>
<script src="../src/models/multiBar.js"></script>
<script src="../src/models/multiBarChart.js"></script>
<script>
var negative_test_data = new d3.range(0,3).map(function(d,i) { return {
key: 'Stream ' + i,
values: new d3.range(0,11).map( function(f,j) {
return {
y: 10 + Math.random()*100 * (Math.floor(Math.random()*100)%2 ? 1 : -1),
x: j
}
})
};
});
function dataFactory(seriesNum, perSeries) {
return new d3.range(0,seriesNum).map(function(d,i) { return {
key: 'Stream ' + i,
values: new d3.range(0,perSeries).map( function(f,j) {
return {
y: 10 + Math.random()*100,
x: j
}
})
};
});
}
defaultChartConfig("chart1", negative_test_data, {
barColor: d3.scale.category20().range(),
delay: 1200,
groupSpacing: 0.1,
reduceXTicks: false,
staggerLabels: true
});
defaultChartConfig("chart2", dataFactory(3,11), {
delay: 0,
transitionDuration:0,
groupSpacing: 0.2
});
defaultChartConfig("chart3",dataFactory(1,15),{
groupSpacing: 0,
delay:0
});
defaultChartConfig("chart4",dataFactory(18,7),{
delay:800
});
defaultChartConfig("chart5",dataFactory(1,1),{
delay:0
});
defaultChartConfig("chart6",dataFactory(1,2),{
delay:0
});
defaultChartConfig("chart7",dataFactory(0,0),{
delay:0
});
function defaultChartConfig(containerId, data, chartOptions) {
nv.addGraph(function() {
var chart;
chart = nv.models.multiBarChart()
.margin({bottom: 100})
.transitionDuration(300)
;
chart.options(chartOptions);
chart.multibar
.hideable(true);
chart.xAxis
.axisLabel("Current Index")
.showMaxMin(true)
.tickFormat(d3.format(',0f'));
chart.yAxis
.tickFormat(d3.format(',.1f'));
d3.select('#' + containerId + ' svg')
.datum(data)
.call(chart);
nv.utils.windowResize(chart.update);
chart.dispatch.on('stateChange', function(e) { nv.log('New State:', JSON.stringify(e)); });
return chart;
});
}
</script>