Pie Chart With Outer Border
HTML
<script src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.19/require.min.js"></script>
<script src="//webdetails.github.io/ccc/charts/lib/amd/require.config.js"></script>
<script src="//webdetails.github.io/ccc/charts/lib/q01-01.js"></script>
<div id="cccExample" />
JavaScript
// margin
var margin = {top: 20, right: 20, bottom: 20, left: 20},
width = 500 - margin.right - margin.left,
height = 500 - margin.top - margin.bottom,
radius = width/2;
// color range
var color = d3.scaleOrdinal()
.range(["#BBDEFB", "#90CAF9", "#64B5F6", "#42A5F5", "#2196F3", "#1E88E5", "#1976D2"]);
// pie chart arc. Need to create arcs before generating pie
var arc = d3.arc()
.outerRadius(radius - 10)
.innerRadius(0);
// donut chart arc
var arc2 = d3.arc()
.outerRadius(radius - 10)
.innerRadius(radius - 70);
// arc for the labels position
var labelArc = d3.arc()
.outerRadius(radius - 40)
.innerRadius(radius - 40);
// generate pie chart and donut chart
var pie = d3.pie()
.sort(null)
.value(function(d) { return d.count; });
// define the svg for pie chart
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
// define the svg donut chart
var svg2 = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
// import data
d3.csv("data.csv", function(error, data) {
if (error) throw error;
// parse data
data.forEach(function(d) {
d.count = +d.count;
d.fruit = d.fruit;
})
// "g element is a container used to group other SVG elements"
var g = svg.selectAll(".arc")
.data(pie(data))
.enter().append("g")
.attr("class", "arc");
// append path
g.append("path")
.attr("d", arc)
.style("fill", function(d) { return color(d.data.fruit); })
// transition
.transition()
.ease(d3.easeLinear)
.duration(2000)
.attrTween("d", tweenPie);
// append text
g.append("text")
.transition()
.ease(d3.easeLinear)
.duration(2000)
.attr("transform",...