From the famous Yoda quote:
Do or do not, ther's no try.
You can visualize it at http://bl.ocks.org/mtorchiano/9c08609add5b6ac2b762
This gist is based on Mike Bostock's gist https://gist.github.com/mbostock/3887235
license: gpl-3.0 |
From the famous Yoda quote:
Do or do not, ther's no try.
You can visualize it at http://bl.ocks.org/mtorchiano/9c08609add5b6ac2b762
This gist is based on Mike Bostock's gist https://gist.github.com/mbostock/3887235
option | prob | |
---|---|---|
Do | .5 | |
DoNot | .5 | |
Try | 0 |
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
.arc text { | |
font: 16px sans-serif; | |
text-anchor: middle; | |
} | |
.arc path { | |
stroke: silver; | |
} | |
</style> | |
<body> | |
<script src="//d3js.org/d3.v3.min.js"></script> | |
<script> | |
var width = 960, | |
height = 500, | |
radius = Math.min(width, height) / 2; | |
var color = d3.scale.ordinal() | |
.range(["white", "black", "red"]); | |
var arc = d3.svg.arc() | |
.outerRadius(radius - 50) | |
.innerRadius(0); | |
var labelArc = d3.svg.arc() | |
.outerRadius(radius - 10) | |
.innerRadius(radius - 10); | |
var pie = d3.layout.pie() | |
.sort(null) | |
.value(function(d) { return d.prob; }); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height) | |
.append("g") | |
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")"); | |
d3.csv("data.csv", cnvrt, function(error, data) { | |
if (error) throw error; | |
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.option); }); | |
g.append("text") | |
.attr("transform", function(d) { return "translate(" + labelArc.centroid(d) + ")"; }) | |
.attr("dy", ".35em") | |
.text(function(d) { return d.data.option; }); | |
}); | |
function cnvrt(d) { | |
d.prob = +d.prob; | |
return d; | |
} | |
</script> |