Last active
August 29, 2015 14:04
-
-
Save erizhang/7808656348c953e50681 to your computer and use it in GitHub Desktop.
Generate a donut chart in d3js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script> | |
</head> | |
<body> | |
<script> | |
var data = [21, 32, 35, 64, 83]; | |
var color = d3.scale.category10(); | |
var pie = d3.layout.pie(); | |
var arcData = pie(data); | |
var arcGenerator = d3.svg.arc() | |
.innerRadius(80) | |
.outerRadius(150) | |
.startAngle(function(d){ | |
return d.startAngle; | |
}) | |
.endAngle(function(d){ | |
return d.endAngle; | |
}) | |
d3.select('body').append('svg') | |
.attr('width', 500) | |
.attr('height', 500) | |
.append('g').attr('transform', 'translate(200, 175)') | |
.selectAll('path').data(arcData).enter() | |
.append('path').attr('d', arcGenerator).style('fill', function(d, i){ | |
return color(i); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment