Bar Chart
NewA responsive SVG bar chart. Bars grow in on view, hovering or focusing a group shows a readout, and an optional second series compares periods.
motionutils@soultel/use-reduced-motion-safe
Revenue 2026$340,500Up 26.4% on 2025. Hover or tab into the bars.
Installation
$ pnpm dlx shadcn@latest add @soultel/bar-chartNo namespace set up? npx shadcn@latest add https://asafefe.dev/r/bar-chart.json works too.
Manual installation
- 1. Install the dependencies.
terminal1 lines npm install motion - 2. Copy the source from the Code tab into components/bar-chart.tsx.
Usage
import { BarChart } from "@/components/bar-chart"
const revenue = [
{ label: "Jan", value: 18400, compare: 15200 },
{ label: "Feb", value: 21900, compare: 16800 },
{ label: "Mar", value: 24300, compare: 19100 },
]
export function Revenue() {
return (
<BarChart
data={revenue}
seriesLabel="2026"
compareLabel="2025"
format={(v) => `$${Math.round(v / 1000)}k`}
/>
)
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
| data | { label: string; value: number; compare?: number }[] | - | One group per label. Add compare for a lighter bar beside each one. |
| seriesLabel / compareLabel | string | "Current" / "Previous" | Series names for the legend and tooltip. |
| format | (value: number) => string | - | Formats axis ticks and tooltip values. |
| height | number | 260 | Chart height in px. The width follows the container. |
| ticks | number | 4 | Approximate number of grid lines. Ticks land on round numbers. |
| onBarClick | (datum, index) => void | - | Called on click or Enter. Arrow keys move between groups. |
| label | string | "Bar chart" | Accessible name for the chart. |
