Skip to content

Instantly share code, notes, and snippets.

@romsson
Created May 11, 2018 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romsson/7126622f77ef6a195a37c2c690e42139 to your computer and use it in GitHub Desktop.
Save romsson/7126622f77ef6a195a37c2c690e42139 to your computer and use it in GitHub Desktop.
[introd3] pie chart
license: mit
<!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