A donut chart in After Effects is the one every tutorial makes look easy. Draw a circle, add a fat stroke, animate Trim Paths. Done in five minutes.
That's one slice. A donut chart has several, and every slice needs to know about every other slice. This post covers the manual technique, the problems that show up once you go past one segment (gaps, round caps, labels, rounding), and how aeChart builds donuts, pies and semi-donuts from a CSV.
As always, the data has to get into After Effects first. The CSV import guide has the details.
The Trim Paths technique
The standard build:
- One shape layer per segment, each with an Ellipse, a thick Stroke and Trim Paths.
- Each segment's Start is the sum of all previous values as a percentage of the total. Its End is that plus its own share.
- Offset rotates the whole thing to where you want the chart to start. Here's the Start expression for one segment:
f = footage("energy.csv");
i = index - 2;
total = 0;
before = 0;
for (r = 0; r < 5; r++) {
v = parseFloat(f.dataValue([1, r]));
total += v;
if (r < i) before += v;
}
before / total * 100
End is the same with r <= i. Animate the reveal with a progress value on top and you've got a working donut.
Where a donut chart in After Effects gets fiddly
Every slice depends on every other slice
Look at that loop. Every segment reads every row. Change one value and all the segments move, which is correct, but it means there's no such thing as "just fixing one slice." Add a sixth row and you duplicate a segment, bump the loop count in five expressions and check the colours still line up. The 5 in that loop is a trap waiting for next quarter's data.
Round caps eat your gaps
Gaps between segments look clean. The natural way to make them is to shave a few degrees off each segment's end. Then you turn on Round Cap because rounded segments look nicer, and your gaps vanish.
A round cap extends the stroke by half its width past the trim point, on both ends. With a 60 px stroke, every segment grows 30 px in each direction. On a 300 px radius that's 0.1 radians, roughly 5.7°, per end. Your neat 2° gap just became an overlap of about 9°.
So you convert the cap extension into degrees and subtract it from every segment. Which depends on the stroke width and the radius. Which you'll want on sliders. You see the pattern.
Butt caps have their own quirk on thick rings: the cut runs straight out from the centre, so a gap is a wedge, narrow on the inside, wide on the outside. Not wrong, just something to know before the art director asks why the gaps "look uneven."
Where does zero degrees even point?
Trim Offset starts wherever the ellipse path starts. JavaScript's Math.sin() and Math.cos() consider 0° to be 3 o'clock. And After Effects' y-axis points down, so the "counter-clockwise" from your school maths book runs clockwise on screen. Labels end up a quarter turn away from their slice, or mirrored, until you've lined up all three systems. Everyone does this at least once. Some of us twice.
Labels and small slices
Labels usually sit at each segment's mid-angle, pushed outwards: cos(angle) * radius and sin(angle) * radius, with the angle from the step above. Big slices are easy. Three small slices next to each other put three labels on top of each other, and there's no expression one-liner for "please don't overlap."
Percentages that add up to 99.9
Show percentages rounded to one decimal and three equal thirds become 33.3 + 33.3 + 33.3 = 99.9. Someone will notice. It's always the person who signs the invoice.
Pie and semi-donut variants
A pie is a donut where the stroke width equals the radius and the ellipse is half the size. Works fine, but now your label radius, gap maths and centre number all change. A semi-donut (the gauge look) halves every trim range and rotates the start to 9 o'clock. Same chart, different maths, again.
How aeChart builds a donut chart
With aeChart:
- Choose CSV... and check one number column.
- Type: Donut, Style: Donut, Pie or Semi-Donut.
- Center: Total adds up all rows, or pick a single row (say, Renewables) to show its value with the name underneath.
- Build Comp. If your numbers already add up to 100, aeChart treats them as percentages. The centre shows a percentage for a single row, and for a pie it leaves out the total row instead of announcing "Total: 100."
On CHART CTRL you get the donut-specific controls:
- Ring Thickness: set it to the full radius and the donut becomes a pie.
- Segment Gap, Start Angle and Arc Angle (180 = semi-donut, 360 = full ring).
- Center to switch between the total and a single row after the build.
- Series 1–6 Color. Segments beyond six reuse the swatches.
- The usual timing, number format, Count Up and visibility switches. Turning a donut into a pie or a gauge is a slider, not a rebuild. When the numbers change, Update Data brings in the new CSV. And it's all native layers and expressions, so the comp renders anywhere, with or without aeChart installed.
Should it even be a donut?
Honest opinion: a donut is great for one share of a whole. "38% of our energy is renewable" with that one segment highlighted and the number big in the middle? Perfect. A donut with nine similar-sized slices is a guessing game. If people have to compare slices against each other, a bar chart does it better, and you'll skip the label collisions too.