Pie Chart Update, III
A pie chart with a donut layout transitions between two datasets, apples and oranges, loaded from a TSV file. The view shows the same arcs morphing between different values, with missing entries treated as zero to maintain object constancy. Two radio buttons switch the active dataset, triggering a 750-millisecond arc tween using D3’s `transition.attrTween` and `d3.interpolate`, which updates the stored angles in `_current`. The chart uses D3 v3’s `d3.layout.pie`, `d3.svg.arc`, and SVG `path` elements, with a timed automatic switch to oranges after two seconds.
AI-generated descriptionThe easiest way to transition between pie charts with differently-sized datasets (while maintaining object constancy) is to set the missing values to zero.
function type(d) {
d.apples = +d.apples || 0;
d.oranges = +d.oranges || 0;
return d;
}
Next: Static Data-Join<br> Previous: Animation