Skip to content

Instantly share code, notes, and snippets.

@curran
Last active November 21, 2015 00:55
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 curran/af6f88e15c3fee137e55 to your computer and use it in GitHub Desktop.
Save curran/af6f88e15c3fee137e55 to your computer and use it in GitHub Desktop.
Introducing d3.layout.pie

This is a small code example that shows what d3.layout.pie(). It adds properties including "startAngle", "endAngle" for the slices of a pie chart. This is example 24 from the screencast Splitting Charts.

MIT License

web counter
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>D3 Example</title>
<script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
</head>
<body>
<script>
var sliceSizeColumn = "population";
var pie = d3.layout.pie();
function render(data){
pie.value(function(d) {
return d[sliceSizeColumn];
});
var pieData = pie(data);
d3.select("body").append("pre")
.text(JSON.stringify(pieData, null, 2));
}
function type(d){
d.population = +d.population;
return d;
}
d3.csv("religionWorldTotals.csv", type, render);
</script>
</body>
</html>
religion population
Christian 2173100000
Muslim 1598360000
Unaffiliated 1126280000
Hindu 1032860000
Buddhist 487320000
Folk Religions 404890000
Other Religions 57770000
Jewish 13640000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment