Components / Data
Bar Chart
Bars that grow in as they scroll into view, with hover tooltips.
Weekly visitors
MonTueWedThuFriSatSun
Installation
Requires React 18+ and Tailwind CSS.
- 1
Install dependencies
$ npm install motion - 2
Add the component
Copy the code from the Code tab above into
components/ui/bar-chart.tsx. - 3
Use it
example.tsximport { BarChart } from "@/components/ui/bar-chart"; const data = [ { label: "Mon", value: 1240 }, { label: "Tue", value: 1980 }, { label: "Wed", value: 1610 }, { label: "Thu", value: 2450 }, { label: "Fri", value: 2130 }, { label: "Sat", value: 980 }, { label: "Sun", value: 760 }, ]; export default function BarChartDemo() { return ( <div className="w-full max-w-md"> <p className="mb-6 text-sm font-medium text-zinc-900 dark:text-white">Weekly visitors</p> <BarChart data={data} height={180} /> </div> ); }
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| data | { label: string; value: number }[] | — | Bars to show. |
| height | number | 200 | Chart height (px). |
| formatValue | (value: number) => string | — | Tooltip formatting. |