Build an Animated Top-10 Bar Chart Race Infographic in One HTML File

You get a single HTML file with an animated top-10 bar chart race. It has play, pause and a year scrubber, smooth rank swaps, and a static final-ranking view for users who prefer reduced motion.

The prompt

Prompt
Act as a senior data-visualization developer who builds polished, accessible infographics in plain HTML, CSS and JavaScript.

Build "Marlow Library Loans Race", a ranked top-10 bar chart race. It shows physical loans, in thousands, at 14 branches of a fictional city library from 2015 to 2024. Hardcode realistic sample data with clear plot twists:
- The central branch starts first and fades.
- A new branch climbs from last to fourth.
- A 2021 closure dips nearly every total.

Add a one-line annotation for each year.

Rules:
- Interpolate values between years and slide bars smoothly to their new rank every frame.
- Bars that fall out of the top 10 fade out below the chart.
- Scale bars to the current leader and show a large faded year watermark.
- Controls: a Play/Pause/Replay button and a year scrubber range input that pauses playback. Space toggles play, the left and right arrows step one year, and Home and End jump to the ends.
- Add a Race / Final ranking toggle. The final view lists the 2024 top 10 with each value and the places gained or lost since 2015.
- With prefers-reduced-motion, open on the final ranking. In Race view, advance one year at a time with no sliding.
- Color bars by four districts and include a legend. Use a warm off-white background, dark ink text and 44px touch targets. The layout must work from 360 to 1280px wide.
- Use no external libraries, fonts or storage. Add a polite live region that announces the top three when paused.

Output format: one complete HTML file in a single code block, then 3 short ideas to extend it.

Example output

One HTML file. Save it and open it in any browser.Open full screen

Example: Marlow Library Loans Race, a top-10 bar chart race of library branches from 2015 to 2024.

Press Play or Space to watch 14 branches race. The bars slide smoothly as ranks change. Drag the year slider to scrub, or use the arrow keys, Home and End to jump between years. Each year shows a short note, such as the 2021 closure dip. Switch to Final ranking to see the 2024 top 10 with places gained since 2015. Reduced-motion users start on that static view.

Written by AI from this prompt. Your results will vary.

Tips and common edits

Why this works

  • Interpolating values and easing each bar toward its rank target every frame gives smooth reorders without any chart library.
  • Hardcoded data with named plot twists and yearly notes makes the race tell a story instead of shuffling random bars.
  • A separate static final-ranking view plus stepped playback means reduced-motion users get the full story with no sliding.

Paste the prompt into ChatGPT, Claude or Gemini. Save the returned code as an .html file and open it in any browser, or view it in the chat's preview or canvas panel.

Common edits

  • Swap the dataset for your own top-10 topic, such as city populations or product sales, and adjust the year range and notes.
  • Change SPEED to make the race faster or slower, or recolor the four district swatches to match your brand.

Prompt details

By
Prompts-GPT editors
Published

Did this prompt work?

Keep exploring

More in Infographics