Built with blockbuilder.org
Created
May 11, 2018 05:49
-
-
Save romsson/7126622f77ef6a195a37c2c690e42139 to your computer and use it in GitHub Desktop.
[introd3] pie chart
This file contains 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
license: mit |
This file contains 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> | |
<meta charset="utf-8"> | |
<style> | |
.arc path { | |
stroke: #fff; | |
} | |
</style> | |
<body> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script> | |
var data = [20, 30, 40]; | |
var width = 960, | |
height = 500, | |
radius = Math.min(width, height) / 2; | |
var arc = d3.arc() | |
.outerRadius(radius - 10) | |
.innerRadius(0); | |
var pie = d3.pie() | |
// .sort(null) | |
.value(function(d) { return d; }); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height) | |
.append("g") | |
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")"); | |
var g = svg.selectAll(".arc") | |
.data(pie(data)) | |
.enter() | |
.append("g") | |
.attr("class", "arc"); | |
g.append("path") | |
.attr("d", arc); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment