-
Notifications
You must be signed in to change notification settings - Fork 9
/
13_donut_chart.html
64 lines (47 loc) · 1.09 KB
/
13_donut_chart.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
<!doctype html>
<html>
<head>
<title>D3 tutorial</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
</head>
<body>
<script>
var data = [10, 50, 80];
var r = 300;
var canvas = d3.select("body")
.append("svg")
.attr("width", 1500)
.attr("height", 1500);
var color = d3.scale.ordinal()
.range(["red", "blue", "yellow"])
var group = canvas.append("g")
.attr("transform", "translate(300,300)");
var arc = d3.svg.arc()
.innerRadius(0)
.outerRadius(r);
var pie = d3.layout.pie()
.value(function (d) {
return d;
})
var arcs = group.selectAll(".arc")
.data(pie(data))
.enter()
.append("g")
.attr("class", "arc");
arcs.append("path")
.attr("d", arc)
.attr("fill", function (d) {
return color(d.data);
});
arcs.append("text")
.attr("transform", function (d) {
return "translate(" + arc.centroid(d) + ")";
})
.attr("text-anchor", "middle")
.attr("font-size", "1.5em")
.text(function (d) {
return d.data;
})
</script>
</body>
</html>