-
Notifications
You must be signed in to change notification settings - Fork 0
/
d3_austin.html
70 lines (60 loc) · 1.17 KB
/
d3_austin.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>D3</title>
<script type="text/javascript" src="https://d3js.org/d3.v5.js"></script>
</head>
<body>
<!-- <script type="text/javascript" src="example_script.js"></script> -->
<div id="chart"></div>
<script>
var dataset = [{
label: 'Abulia',
count: 10
},
{
label: 'Betel',
count: 20
},
{
label: 'Cantaloupe',
count: 30
},
{
label: 'Dij',
count: 40
}
];
var width = 360;
var height = 360;
var radius = Math.min(width, height) / 2;
var color = d3.scaleOrdinal(d3.schemeCategory10);
var svg = d3.select("#chart")
.append("svg")
.attr("height", height)
.attr("width", width)
.append("g")
.attr("transform", "translate(" +
(width / 2) + "," +
(height / 2) + ")");
var arc= d3.arc()
.innerRadius(0)
.outerRadius(radius);
//pie generator
var pie = d3.pie()
.value(function(d){
return d.count;
})
.sort(null);
var path = svg.selectAll("path")
.data(pie(dataset))
.enter()
.append("path")
.attr("d", arc)
.attr("fill", function(d, i){
return color(d.data.label);
});
</script>
</body>
</html>