forked from sdqali/d3-dojo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01-barchart.html
58 lines (55 loc) · 1.1 KB
/
01-barchart.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
<!DOCTYPE html>
<meta charset="utf-8">
<html>
<head>
<title>
Barchart
</title>
<script type='text/javascript' src='/d3/d3.v2.min.js'>
</script>
<style type='text/css'>
.chart rect {
stroke: white;
fill: SteelBlue;
}
</style>
</head>
<body>
<div id="barchart">
</div>
<script type='text/javascript'>
var data = [820, 883, 903, 836, 915, 981, 892, 761, 858, 757, 363];
var chart = d3.select("#barchart").append("svg")
.attr ("class", "chart")
.attr ("width", 1000)
.attr ("height", 20 * data.length);
// Add rectangles
chart.selectAll ("rect")
.data (data)
.enter ()
.append ("rect")
.attr ("width", function (d) {
return d;
})
.attr ("height", 20)
.attr ("y", function (d, i) {
return i * 20;
});
// Add text showing number of deaths
chart.selectAll ("text")
.data (data)
.enter ()
.append ("text")
.text (String)
.attr ("x", function (d) {
return d;
})
.attr ("y", function (d, i) {
return i * 20 + 10;
})
.attr("dy", ".35em")
.attr("dx", "-5")
.attr ("text-anchor", "end");
</script>
</body>
</html>