Created
February 5, 2014 19:38
-
-
Save jarodreyes/8831399 to your computer and use it in GitHub Desktop.
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
<html> | |
<head> | |
<style> | |
.arc path { stroke: #fff; } | |
</style> | |
<script src="https://dl.dropboxusercontent.com/u/10861681/blog-post/d3.v3.min.js"></script> | |
</head> | |
<body> | |
</body> | |
<script> | |
var width = 300; | |
var height = 300; | |
var radius = Math.min(width, height) / 2; | |
var color = d3.scale.ordinal().range(["#fe001b", "#999ca0"]); | |
var arc = d3.svg.arc().outerRadius(radius - 50).innerRadius(25); | |
var pie = d3.layout.pie().sort(null).value(function(d) { | |
return d.count; | |
}); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height) | |
.append("g") | |
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")"); | |
d3.json("https://dl.dropboxusercontent.com/u/10861681/blog-post/data.json", function(error, data) { | |
data.forEach(function(d) { | |
d.count = +d.count; | |
}); | |
var g = svg.selectAll(".arc") | |
.data(pie(data)) | |
.enter().append("g") | |
.attr("class", "arc"); | |
g.append("path") | |
.attr("d", arc) | |
.style("fill", function(d) { return color(d.data.variant); }); | |
var text = g.append("text") | |
.attr("transform", function(d) { return "translate(" + arc.centroid(d) + ")"; }) | |
.attr("dy", "1em") | |
.attr("font-size", "1.5em") | |
.attr("fill","white") | |
.attr("y",-10) | |
.style("text-anchor", "middle") | |
text.append("tspan") | |
.text(function(d) { return d.data.variant; }); | |
text.append("tspan") | |
.attr("dy","1em") | |
.attr("x",0) | |
.text(function(d) { return d.data.count; }) | |
}); | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment