-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
139 lines (105 loc) · 3 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bullet chart extension for dc.js</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/dc.css" />
<style>
body {
font-family: sans-serif;
padding-top: 70px;
}
.dc-chart g.row {
opacity: .7;
}
.dc-chart .marker {
stroke: #000;
stroke-width: 2px;
}
</style>
</head>
<body>
<div class="block">
<div class="container">
<div class="row bottom-buffer">
<div class="col-md-12">
<div id="simple-bullet-chart">
<h3>
Bullets <small><a class="reset"
href="javascript:bulletChart.filterAll();dc.redrawAll();"
style="display: none;">reset</a></small>
</h3>
<p>
<small>Bullet chart based on dc.js rowchart. </small>
</p>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/d3.v3.min.js"></script>
<script type="text/javascript" src="js/crossfilter.v1.min.js"></script>
<script type="text/javascript" src="js/dc.min.js"></script>
<script type="text/javascript" src="js/dc.bullet.js"></script>
<script type="text/javascript" src="js/colorbrewer.v1.min.js"></script>
<script type="text/javascript">
var bulletChart = dc.bulletChart( "#simple-bullet-chart" );
var colors = (colorbrewer.PuBu[8]).reverse(); // darkest color first
d3.json("data/bullets.json", function (data) {
var ndx = crossfilter(data);
var all = ndx.groupAll();
var titleDim = ndx.dimension(function (d) {
return d.title;
});
function reduceAdd(p, v) {
++p.count;
p.quantity += +v.quantity;
p.target += +v.target;
return p;
}
function reduceRemove(p, v) {
--p.count;
p.quantity -= +v.quantity;
p.target -= +v.target;
return p;
}
function reduceInitial() {
return {count: 0, quantity: 0, target: 0};
}
var titleGroup = titleDim.group().reduce(reduceAdd, reduceRemove, reduceInitial);
bulletChart.width(360)
.height(130)
.margins({top: 20, left: 10, right: 10, bottom: 20})
.group(titleGroup)
.dimension(titleDim)
.markerAccessor( function(d) {
return d.value.target / d.value.count;
})
.valueAccessor( function(d) {
return d.value.quantity;
})
.keyAccessor( function(d) {
return d.key;
})
// assign colors to each value in the x scale domain
.ordinalColors( colors )
.label(function (d) {
return d.key;
})
// title sets the row text
.title(function (d) {
return d.value.quantity;
})
.elasticX(true)
.xAxis()
.ticks(6);
// render charts
dc.renderAll();
});
</script>
</body>
</html>