You've seen them: bars racing past each other while a big year counter ticks from 1960 to 2025. A bar chart race in After Effects looks like a simple idea, sort some bars every frame. It's actually the hardest chart in this series to build by hand, and the one I'd least recommend hand-building.
This post explains why: the keyframe math, the ranking problem, rank swaps, ties, the moving axis, and what all of that does to your preview speed. Then how aeChart builds the same race from a CSV.
The data side matters more here than anywhere else, because a race uses a lot of rows. If you haven't read it, the CSV import guide covers the traps.
Why keyframing it is out of the question
Say you're racing 12 countries over 66 years, 1960 to 2025. That's 12 × 66 = 792 values to keyframe on the bar widths. Then every bar's vertical position changes whenever it overtakes or gets overtaken, so add position keyframes. Then the value labels. You're well past a thousand keyframes, and the client hasn't sent the corrected numbers yet.
Nobody keyframes a bar race twice. So it's expressions.
How the expression version works
Each bar needs to do three things on every frame:
- Work out which period we're in and how far between this year and the next.
- Interpolate its own value.
- Interpolate everyone else's value, count how many are bigger, and use that as its rank. A stripped-down version on a bar's Position:
f = footage("gdp.csv");
period = 1.5;
last = 65;
n = 12;
t = time / period;
r = Math.min(Math.floor(t), last);
k = t - r;
function val(c) {
var a = parseFloat(f.dataValue([c, r]));
var b = parseFloat(f.dataValue([c, Math.min(r + 1, last)]));
return a + (b - a) * k;
}
me = val(index);
rank = 0;
for (c = 1; c <= n; c++) {
if (c != index && val(c) > me) rank++;
}
[value[0], 150 + rank * 70]
It works. And it immediately shows you the next four problems.
Where a bar chart race gets nasty
Bars teleport
rank is a whole number. The moment one bar overtakes another, both jump to their new slots in a single frame. A race needs the swap animated over some time, say half a second, which means each bar has to know its rank a moment ago and blend towards the new one. And if a bar overtakes two others during that half second, the blend has to cope with the target changing mid-move.
Your preview turns into a slideshow
Look at the loop again: every bar evaluates every competitor, every frame. Twelve bars, each reading two cells for each of twelve competitors, is roughly 300 CSV reads per frame just for positions. Add smoothed rank swaps (sampling a few moments in time) and the value labels, which do the same work again, and you're in the thousands per frame. RAM preview goes from "real time" to "go make coffee."
Ties flicker
Two competitors with the same value (it happens a lot with rounded data, and at the start when everything is 0) have no defined order. Depending on floating-point noise, they swap back and forth every frame. You need a tiebreaker, like the column order, baked into the comparison.
The axis has to move
The leader's value sets the scale, and the leader keeps growing. So the axis rescales every frame, which is correct, but the gridlines now have to rescale too, and jump to new "nice" steps (100, 200, 500…) as the numbers grow, fading old lines out and new ones in. Without it, a race from 1960 to 2025 either starts with microscopic bars or ends with bars flying off the screen.
Only the top 10 are visible
You might track 12 competitors but show 10. The ones ranked 11 and 12 need to sit just below the frame and slide in when they climb, instead of popping into existence. More position logic, plus some opacity so a bar half off-screen doesn't look like a mistake.
Colours belong to competitors, not positions
Obvious, but easy to get wrong once you start sorting things. Colour has to follow the column, not the rank. Same for the name label and the value label that ride along with each bar.
Easing between years
Ease each year's transition and the whole race pulses: speed up, slow down, speed up, every 1.5 seconds. It looks like the chart is hiccupping. My take: interpolate values linearly between periods and ease only the rank swaps. Continuous growth, smooth overtakes.
How aeChart builds a bar chart race
With aeChart:
- Choose CSV... Each row is a point in time (a year, a month), each number column is one competitor. Up to 200 rows and 12 competitors, so 1960 to 2025 fits comfortably.
- Type: Race, Style: Bar Race. Check the competitors you want. Check just one and all number columns race.
- Set Period (seconds per row) and Swap (how long a bar takes to move to its new rank). Comp Length shows you how long the result will be before you build.
- Build Comp. The race is built from regular shape and text layers plus the CHART CTRL null, where you can adjust Period Duration and Swap Time afterwards without rebuilding. Number formatting, gridlines, axis labels, colours and the background are there too, same as every other aeChart chart.
The data updates the same way as everything else: Update Data with a new CSV, and if the number of years changed, aeChart offers a rebuild that keeps your CHART CTRL tweaks.
One opinion on length
66 years at 1.5 seconds per year is 99 seconds. That's long for a Reel, and most viewers will have made up their minds about the winner by second 30. If it's for social, consider fewer years, a shorter period, or starting where the story starts. If 1960 to 1990 is just the same three countries in the same order, nobody will miss it.