Components / Data
Line Chart
A smooth line that draws itself, with a gradient fill and hover crosshair.
Revenue
$34,700
JanFebMarAprMayJunJul
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/line-chart.tsx. - 3
Use it
example.tsx"use client"; import { LineChart } from "@/components/ui/line-chart"; const data = [ { label: "Jan", value: 3200 }, { label: "Feb", value: 4100 }, { label: "Mar", value: 3800 }, { label: "Apr", value: 5200 }, { label: "May", value: 4900 }, { label: "Jun", value: 6400 }, { label: "Jul", value: 7100 }, ]; export default function LineChartDemo() { return ( <div className="w-full max-w-md"> <p className="text-sm font-medium text-zinc-900 dark:text-white">Revenue</p> <p className="mb-6 text-2xl font-semibold text-zinc-900 dark:text-white">$34,700</p> <LineChart data={data} height={160} formatValue={(v) => `$${v.toLocaleString("en-US")}`} /> </div> ); }
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| data | { label: string; value: number }[] | — | Points to plot. |
| height | number | 200 | Chart height (px). |
| formatValue | (value: number) => string | — | Tooltip formatting. |