-
Notifications
You must be signed in to change notification settings - Fork 0
/
动态圆环图.html
57 lines (49 loc) · 1.44 KB
/
动态圆环图.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
html, body { padding:0; margin:0; }
</style>
</head>
<body>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
var chart = {};
chart.options = {
width: 500,
height: 400,
endAngle: 2 * Math.PI,
margin: 25,
colors: d3.scaleOrdinal(d3.schemeCategory10)
};
chart.renderXAxis = function() {
var xScale = d3.scaleLinear()
.domain([0, 100])
.range([0, this.options.width - 100 ]),
xAxis = d3.axisBottom().scale(xScale);
d3.select('svg').append('g')
.attr('class', 'x-axis')
.attr('transform', 'translate(' + this.options.margin + ',' + (this.options.height - this.options.margin) + ')' ).call(xAxis);
this.renderXLines();
};
chart.init = function() {
d3.select('body').append('svg')
.attr('width', chart.options.width)
.attr('height', chart.options.height);
this.renderXAxis();
}
chart.renderXLines = function() {
d3.selectAll('.x-axis .tick')
.append('line')
.attr('stroke', '#ccc')
.attr('x1', 0)
.attr('y1', 0)
.attr('x2', 0)
.attr('y2', - this.options.height + 2 * this.options.margin)
}
chart.init();
</script>
</body>
</html>