Bar chart race and animated charts: how to make them
A bar chart race re-sorts bars as values change over time. Build one from a CSV with GSAP or D3, render it to MP4, and animate bar and line charts.
- For
- Developers and analysts who want a ranking-over-time video from their data
- Written for
- Claude CodeCodexCursorGitHub CopilotGemini CLIOpenCodeAny agent that reads SKILL.md folders
- Time
- 12 min read · updated Nov 20, 2026
The short answer
- A bar chart race is an animated bar chart of a ranking over time. Each bar is one name, its length is that name’s value at the moment shown, and the bars re-sort as the values change, so you watch one overtake another while a large label counts through the years or quarters.
- To make one, start from a table with a row per name and a column per period. Interpolate between the periods to get in-between frames, rank the names in every frame, then animate each bar’s length and its move from one rank to the next. Draw it with GSAP or D3 on a web page, and render the page frame by frame when you need an MP4. The same tools animate bar and line charts.
What a bar chart race shows
A bar chart race answers one question: who led, and when did the lead change hands? It suits a ranking across many periods, such as products by installs per quarter, cities by trips per year or teams by points per week. Each frame is an ordinary sorted bar chart. The motion between frames is what shows the overtakes.
When the question is different, pick a different animated chart:
The data: a row per name, a column per period
Lay the data out with one row per name and one column per period, and use 0 where a name has no value yet. Flourish’s bar chart race page describes the same layout, so one spreadsheet works for both routes. The numbers below are made-up sample data: six fictional bike-share networks and their trips per year, in thousands.
Mike Bostock’s Bar Chart Race, Explained notebook on Observable uses a long layout instead: one row per name and date, with date, name and value columns and an optional category for color. Either works. The code only needs a value for each name in each period.
How it works: keyframes, ranks and slides
Bostock’s notebook explains the method step by step. Four ideas do the work:
- Interpolate between periods. In the data, ranks change once per period. If a bar slid to its new rank over the whole period, many bars would drift at once and the race would be hard to follow. So the notebook splits each period into 10 keyframes, with every value interpolated in a straight line from one period to the next.
- Rank every keyframe. Sort the keyframe’s values from largest to smallest and number them. A rank is a whole number, so a bar’s rank jumps from one keyframe to the next, and animating between the two turns that jump into a short slide: the overtake.
- Rank the names below the cut-off too. The notebook shows 12 bars but ranks every name, and puts all the rest one row below the last visible bar. A name that climbs into the top group slides in from below, and one that drops slides out, instead of popping in or out.
- Rescale to the leader. In each keyframe the scale’s top is the leading bar’s value, so the leader always fills the width and the others are measured against it.
The notebook moves from keyframe to keyframe in 250 milliseconds with linear easing, so each period lasts 2.5 seconds and the race runs at a constant speed. Its value labels use tabular figures, digits of equal width, so the counting numbers don’t jitter.
Build it with GSAP: a complete page
This file is a whole bar chart race: the sample data, about 70 lines of JavaScript and GSAP 3.14 from a CDN. Save it as index.html and open it in a browser, and the race plays. It is also a HyperFrames composition, so it renders to MP4 without changes.
keyframe()interpolates every value at one point between two periods and ranks the names. Every name pastTOPgets rankTOP, one row below the chart, whichoverflow: hiddenclips, so names slide in and out at the bottom edge.render(t)draws any moment.tcounts keyframes, and between two keyframes it interpolates both the values and the ranks, so a bar glides from one row to the next instead of jumping.- The leading value sets the scale, so the leader is always
WIDTHpixels long and the others shrink against it as it grows. - One GSAP tween with
ease: 'none'movestfrom the first keyframe to the last, and itsonUpdatecallsrender. GSAP can tween a property of any object, not only CSS, andnoneis its linear ease. Without it the tween takes GSAP’s default ease,power1.out, and the race slows down toward the end. - A bar moving up is drawn in front, so the one overtaking covers the one it passes. Names are set with
textContent, so text in the CSV is never read as HTML. - There is no axis. The value printed at the end of each bar does that job; Bostock’s notebook draws one with D3’s
axisTopif you want gridlines. - The
data-attributes are for HyperFrames: those on#rootset the video’s size and length, and the two on#charttell its checker that bars crossing and waiting below the edge are on purpose. A browser ignores them.
In our test (Chromium 153 through Playwright 1.63, HyperFrames 0.8.192), the page played in a plain browser tab with no errors, and the period label read 2019, 2021 and 2024 at 1, 6 and 14.5 seconds.
Render it to an MP4
Everything on screen is a function of t, so a renderer can jump to any frame and get the same picture every time. HyperFrames does this: it finds the timeline the page puts in window.__timelines, seeks it to each frame in headless Chrome and encodes the frames with FFmpeg. In a folder with index.html, run:
In our test on an M4 Mac mini, check passed and the 14.5-second race rendered in under 8 seconds to a 1920×1080 H.264 MP4 at 30 frames a second, about 0.7 MB. The frames matched the numbers the code computes: at 9.5 seconds, 80% of the way from 2022 to 2023, Linden read 1,226 and Harbor 1,066, and Summit had entered from below while Northgate had dropped out.
HyperFrames needs Node.js 22 or newer and FFmpeg. HTML to video covers the other ways to turn a page into an MP4, including a frame-by-frame script of your own with Playwright and FFmpeg, and why a screen recording can stutter.
The same race in D3
Bostock’s notebook builds the race with D3 transitions: for each keyframe it sets the scale, joins the top names to bars keyed by name, starts a 250-millisecond linear transition and waits for it to end before the next. D3’s own defaults are 250 milliseconds with cubic easing, which eases in and out of every keyframe, so the notebook sets linear easing.
D3 transitions run on d3-timer, which uses requestAnimationFrame and performance.now, so they play in real time. That suits a page someone watches. A frame-by-frame renderer has to set the time itself, so keep D3 for what it does well, scales and the data join, and call it from the same render(t). Replace steps 3 and 4 of the page above with this:
Then load D3 after GSAP and give SVG text a font, in the <head>. Steps 1, 2 and 5 stay as they are.
.data(rows, (d) => d.name)keys each bar by its name, so a bar stays with its name however the order changes.selection.raise()moves an element to the end of its parent, and SVG draws later elements on top, so a rising bar passes in front.- In our test the D3 version showed the same values at the same moments as the GSAP one, played in a browser tab and passed
hyperframes check.
Animated bar charts and line charts
Most other animated charts are simpler than a race: a few tweens on one timeline. Two common ones follow, both tested as one HyperFrames composition.
An animated bar chart
The bars grow from zero one after another while their values count up. gsap.from() animates from the values you give to the ones the element already has, so set each bar’s final height and tween from 0. stagger starts each bar a little after the one before, and snap rounds the counting number to a whole number on every frame, not only at the end.
#cols is a flex row with align-items: flex-end, so each column grows up from the baseline, and each value sits in a <b> placed above its column.
An animated line chart
Set pathLength="1" on the line so dash lengths are measured as a share of the whole path. A dash array of 1 is then one dash as long as the line, and a dash offset of 1 shifts it out of sight. Tweening the offset from 1 to 0 draws the line from start to end; at 0.5 half of it shows.
Tween the offset as an attribute, as above. GSAP rounds CSS pixel values to whole numbers during a tween by default, so tweening the CSS property strokeDashoffset from 1px to 0px jumps from hidden to fully drawn halfway through. That is what our first test did.
Without code
If you don’t need the code, online chart tools have bar chart race templates. Flourish, for example, takes a spreadsheet with a row per participant and a column per period, adds captions and images, and shares the race as an interactive chart by link or embed. If you need a video file, check the export options first: Flourish’s page lists PNG, JPEG and SVG downloads on its Presenter, Publisher and Enterprise plans. Bostock’s notebook can also be forked on Observable with your own data dropped in.
Let an agent build it
A coding agent such as Claude Code, Codex or Cursor can write the page above from your CSV and run the render. For a finished film rather than a starting point, Lookbk’s chart skills give the agent a designed template, a brief whose limits a script checks before anything renders, and the scripts that render it on your machine.
- Ranking Race Film: a 32 to 36 second 1080p bar chart race of up to 10 names over 6 to 12 periods, with lifted overtakes, a period label that rolls like a counter, up to three callouts placed where no bar runs under them, a winner plate for the leader and an original soundtrack written by code. It refuses a brief until the data is either marked as illustrative or given a source line.
- Data Story: Bars: a 12-second animated bar chart from a CSV. A script takes the first text column as the labels and the first numeric column as the values; the bars grow with counting values, a trend line draws through them and one bar gets a callout. Up to 12 bars, positive values, no soundtrack.
- Line Story Film: a 40-second animated line chart told like a newspaper graphic. The camera follows the line as it draws, slows at each event you name and ends on the change from start to end, with a script that drafts the brief from a CSV and an original soundtrack.
- Infographic Poster: for a still instead of a video, a one-page poster with bar, column and ring charts drawn as SVG from a CSV or JSON file, checked for overflow and contrast, as a PNG, a vector PDF and an HTML page.
The three films render with HyperFrames and need Node.js 22 or newer and FFmpeg, and HyperFrames downloads its own Chrome; the poster needs Node.js 18 or newer and Chrome. Animated chart videos lists every chart skill and the data each one takes.
Common problems
Two bars flicker past each other again and again
Their values stay nearly equal for a while, so their ranks swap on many keyframes. Round the data, or keep the old order until the gap is bigger than a small share of the leader’s value.
Bars pop in or out instead of sliding
Rank every name, not only the ones on screen, give the rest the first rank below the chart, and clip the chart with
overflow: hidden.The numbers jitter as they count
Set
font-variant-numeric: tabular-numson the value labels, so every digit is the same width.The race speeds up and slows down
An ease is shaping the time. Use
ease: 'none'on the GSAP tween that movest, ord3.easeLinearon D3 transitions. GSAP’s default ease ispower1.out, and D3’s is cubic.The MP4 stutters but the page plays smoothly
It was recorded in real time. Render it frame by frame from
render(t)as above.The line chart appears all at once
GSAP rounded a CSS pixel value. Tween
attr: { 'stroke-dashoffset': 0 }, or passautoRound: false.
Common questions
- What is a bar chart race?
- An animated horizontal bar chart of a ranking over time. Each bar is a name, its length is the name’s value at that moment, and the bars re-sort as values change, so the viewer sees who overtakes whom and when the lead changes.
- How long should each period last?
- Bostock’s notebook uses 2.5 seconds per period, 10 keyframes of 250 milliseconds, and the page above does the same with
SECONDS = 2.5. Six periods give 12.5 seconds of racing. For a long series, lowerSECONDS. - How many bars should I show?
- As many as stay readable at your video size. The notebook shows 12; the page above shows 5 of its 6 names so you can see one enter and one leave. Change
TOPandROWtogether so the bars fit the chart’s height. - Is the data in this guide real?
- No. The bike-share networks and their numbers are made up. If you publish a race of real data, name the source on screen.
- Can I make a bar chart race without writing code?
- Yes. Online chart tools have bar chart race templates that take the same row-per-name table. A coding agent can also write and render the page above from your CSV, and Ranking Race Film does it as a finished film.
Sources
What this guide says about other companies’ tools comes from their own documentation, checked on Nov 20, 2026.
- Mike Bostock: Bar Chart Race, Explained (Observable, ISC license) (opens in a new tab)
- D3 docs: Joining data (selection.join, key functions) (opens in a new tab)
- D3 docs: Modifying elements (selection.raise) (opens in a new tab)
- D3 docs: Linear scales (opens in a new tab)
- D3 docs: Transition timing (default duration and easing) (opens in a new tab)
- D3 docs: Transition control flow (scheduling, end) (opens in a new tab)
- D3 docs: d3-ease (easeLinear, easeCubic) (opens in a new tab)
- D3 docs: d3-timer (opens in a new tab)
- d3-transition source: schedule.js imports d3-timer (opens in a new tab)
- GSAP docs: Timeline (opens in a new tab)
- GSAP docs: gsap.to() (opens in a new tab)
- GSAP docs: gsap.from() (opens in a new tab)
- GSAP docs: Eases (opens in a new tab)
- GSAP docs: CSSPlugin (autoRound) (opens in a new tab)
- GSAP docs: Attributes (opens in a new tab)
- GSAP docs: Snap (opens in a new tab)
- MDN: pathLength (opens in a new tab)
- MDN: stroke-dashoffset (opens in a new tab)
- MDN: font-variant-numeric (opens in a new tab)
- HyperFrames on GitHub (README and Apache 2.0 license) (opens in a new tab)
- Flourish: Make a bar chart race without coding (opens in a new tab)
Did this guide help?
Read next
All guidesHTML to video: 5 ways to turn HTML into an MP4
Turn HTML into an MP4: render it frame by frame in headless Chrome with FFmpeg, use HyperFrames or Remotion, record the screen, or record a canvas.
How to make an explainer video with code and an AI agent
Script in scenes, storyboard, pick a style, and have a coding agent render your explainer video to MP4 from HTML. Plus when a web tool is the better choice.
HyperFrames tutorial: render an HTML page to MP4
Turn HTML into an MP4 without screen recording: set up HyperFrames, write the video as an HTML page with GSAP, check it, render it, or hand it to an agent.
How to make videos with Claude Code
Three ways to make MP4 videos with Claude Code: Remotion’s skills, HyperFrames, or a ready-made video skill. Setup, a first render and fixes.
See a skill’s result before you install it.
Every skill page shows what it makes, what it needs and which agents can run it.



