Bar Chart Race Without Lying: Entity Keys, Time Slices, and Missing Values
Bar chart races look simple: sort values, animate bar widths, let the labels swap places. The animation is the easy part. The hard part is making sure frame 42 represents the same reality as frame 41 — and that the ranking you show is one the source data actually supports.
These are the data rules we settled on after shipping animated charts from messy spreadsheets. Most of them are boring. All of them prevent a specific, embarrassing bug.
1. Never key by label
A label is display text, not an identity. Companies rename themselves, two rows can share a name, and a spreadsheet export can reorder everything. Key by a stable ID and keep the label as an attribute:
const rows = [ { id: 'acme-001', label: 'Acme', period: '2024-01', value: 120 }, { id: 'acme-001', label: 'Acme Corp', period: '2024-02', value: 143 }, ]; const byEntity = new Map(); for (const r of rows) { if (!byEntity.has(r.id)) byEntity.set(r.id, { id: r.id, label: r.label, values: new Map() }); const e = byEntity.get(r.id); e.label = r.label; // latest display name wins e.values.set(r.period, r.value); } If your source has no ID, derive one from the column that does not change — a ticker, a SKU, a database primary key. If nothing is stable, you do not have a time series; you have a list of screenshots.
2. Build a regular time axis before interpolating
Races need frames at equal time intervals. Source data rarely is. Normalize first:
function timeAxis(first, last, stepMonths) { const out = []; let [y, m] = first.split('-').map(Number); const [ey, em] = last.split('-').map(Number); while (y < ey || (y === ey && m <= em)) { out.push(`${y}-${String(m).padStart(2, '0')}`); m += stepMonths; if (m > 12) { m -= 12; y += 1; } } return out; } Then sample each entity onto that axis. Do not interpolate between whatever two rows happen to be adjacent in the file; gaps of one month and twelve months produce completely different animation speeds from the same input.
3. Decide what a missing value means
There are three honest answers, and picking one silently is how charts lie:
- Not yet reported → carry the last known value forward, but mark the point as carried.
- Zero is meaningful → use zero, and say so in the caption.
- Unknown → leave a gap; do not draw a bar.
Carrying forward is the common default, but it must not look like a fresh measurement. A subtle hollow bar segment or a footnote in the corner is enough. If more than a small share of frames are carried, the race is mostly animation and very little data — that is worth surfacing to the viewer.
4. Use monotone interpolation, not plain cubic
A cubic spline through three points can overshoot. In a ranking chart that means a value dips below zero or a bar briefly grows past its true peak, and nobody notices until someone pauses the video.
function monotoneSample(a, b, c, d, t) { // Fritsch-Carlson style tangent limiting: no overshoot between samples const slope = (n1, n2) => (n2.v - n1.v) / (n2.t - n1.t); const m1 = slope(a, b); const m2 = slope(b, c); const m3 = slope(c, d); const lim = x => Math.sign(x) * Math.min(Math.abs(x), 3 * Math.abs(slope(b, c))); const t1 = lim((m1 + m2) / 2); const t2 = lim((m2 + m3) / 2); const h = c.t - b.t; const s = t / h; return (2*s**3 - 3*s**2 + 1) * b.v + (s**3 - 2*s**2 + s) * h * t1 + (-2*s**3 + 3*s**2) * c.v + (s**3 - s**2) * h * t2; } Linear interpolation is perfectly acceptable too. Smoothness is not accuracy, and a race that runs at 30 fps already looks smooth with linear segments.
5. Break ties deterministically
Two entities with the same value will trade places on every frame if the sort is unstable. Freeze the tie order with the ID:
const ranked = entities .map(e => ({ ...e, current: sample(e, t) })) .sort((a, b) => b.current - a.current || a.id.localeCompare(b.id)); Position interpolation then moves bars between ranks. If an entity enters or leaves the top N, give it an explicit off-screen rank (N + 1) so it slides in and out instead of appearing at a random coordinate.
6. Keep units and scope fixed
The most misleading race is not the one with bad numbers — it is the one where the meaning changes halfway through. Watch for:
- A source switching from monthly to cumulative values in the last quarter.
- A currency conversion applied only to recent rows.
- A company acquisition that merges two entities into one row.
None of these are animation problems. Detect them before rendering: compare row counts and units per period, and if the schema changes, split the video rather than pretending it is one continuous story.
7. The same ranked snapshot drives preview and export
For every frame index, compute one immutable snapshot: rank, value, label and carried flag. Draw from that snapshot in the preview, in the thumbnail, and in the MP4 export. If the ranking is recomputed separately in each path, the paused frame and the exported frame will eventually disagree.
Where this came from
These constraints shape LivelyChart, which I help build. You upload Excel or CSV, describe the scene — a board deck, product launch, QBR or social clip — and it generates matching animated charts, maps the data, and exports MP4, WebM, GIF or PNG up to 4K. The spreadsheet is parsed in the browser and only leaves the device if you ask the AI to edit it.
If you are building your own race, pause on any frame and ask: does this bar represent a real measurement, or an artifact of my interpolation? That question catches most bugs before your viewers do.
Disclosure: I am one of the builders of LivelyChart, linked above.

