Race bar chartPro
Bars that re-rank as values change over time, with play, pause and a scrubber.
$
pnpm dlx shadcn@latest add @lode/race-bar-chartLive preview
App installs by country
Yearly totals, top 8 · drag the slider to scrub
United States
420K
Japan
300K
Germany
260K
United Kingdom
210K
France
190K
Brazil
140K
Mexico
110K
India
90K
Indonesia
40K
Nigeria
201615K
2016
When to use
- Telling how a ranking changed over time: market share by year, top products by week.
- Presentations and landing pages where the motion is the story.
When not to use
- Reading exact values at a moment: use a bar chart with a period picker.
- Trends of one or two series: use a line chart.
Installation
$
pnpm dlx shadcn@latest add @lode/race-bar-chartPro components need an API key and the registry in components.json. See CLI and API keys.
1Install the dependencies
npm install motion lucide-react2Copy the source into your project
Usage
Import it from @/components/ui/race-bar-chart after installing.
example.tsx
import { RaceBarChart } from "@/components/ui/race-bar-chart";
const frames = [
{ label: "2024", values: { Search: 420, Social: 180, Direct: 260 } },
{ label: "2025", values: { Search: 460, Social: 340, Direct: 280 } },
{ label: "2026", values: { Search: 480, Social: 520, Direct: 300 } },
];
export function Race() {
return <RaceBarChart frames={frames} top={5} />;
}API reference
RaceBarChart
Ranked bars that tween between frames and re-order as they overtake.
| Prop | Type | Default | Description |
|---|---|---|---|
| frames | RaceFrame[] | – | { label, values: Record<name, number> }, in time order. |
| top | number | 8 | Bars shown at once. |
| speed | number | 1400 | Milliseconds per frame. |
| colors | Record<string, string> | – | Colour per name; others use the chart palette. |
| format | (n) => string | – | Value at the end of each bar. |
| autoPlay | boolean | true | Start when the chart scrolls into view. |
| loop | boolean | false | Start again after the last frame. |
| rowHeight | number | 34 | Height of each row in px. |
Keyboard interactions
| Keys | Action |
|---|---|
| Tab | Move to play and the time slider |
| Arrow keys | Step through time on the slider |
| EnterorSpace | Play, pause or replay |
Accessibility
- Bars are a list; the current period is announced politely as it changes.
- The slider has the period as its value text.
Motion
- Values ease between frames and rows slide to their new rank.
- With reduced motion nothing autoplays and rows jump instead of sliding.
Responsive behavior
- Name column shrinks on narrow screens; bars fill the rest.
Performance
- One animation frame loop while playing, stopped when paused or finished.
Notes for AI
- Every frame should list the same names; a missing name counts as 0.
- Keep frames to a few dozen; tweening makes them feel continuous.
This page as Markdown, for assistants and coding agents:
/components/race-bar-chart/markdownThe full library index for assistants is at /llms.txt.
Related
Lode·227 doc pages·llms.txt