Components
Line Chart
NativeShows change over time as lines or filled areas, with a crosshair that reads every series at once.
- Visitors
- Sign-ups
| week | Visitors | Sign-ups |
|---|---|---|
| W36 | 4.2K | 310 |
| W37 | 4.8K | 380 |
| W38 | 4.5K | 350 |
| W39 | 5.6K | 520 |
| W40 | 6.1K | 640 |
| W41 | 5.8K | 610 |
| W42 | 7.2K | 880 |
| W43 | 7.9K | 1K |
Installation
npx nook-ui@latest add line-chartPrompt
Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.
Short. For assistants that can run commands in your project.
Add the Nook "Line Chart" component to this project, exactly as Nook ships it.
Shows change over time as lines or filled areas, with a crosshair that reads every series at once.
Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add line-chart`. It writes `components/ui/line-chart.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/line-chart.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:
```tsx
import { LineChart } from "@/components/ui/line-chart";
const DATA = [
{ week: "W36", visitors: 4200, signups: 310 },
{ week: "W37", visitors: 4800, signups: 380 },
{ week: "W38", visitors: 4500, signups: 350 },
{ week: "W39", visitors: 5600, signups: 520 },
{ week: "W40", visitors: 6100, signups: 640 },
{ week: "W41", visitors: 5800, signups: 610 },
{ week: "W42", visitors: 7200, signups: 880 },
{ week: "W43", visitors: 7900, signups: 1040 },
];
export default function LineChartDefault() {
return <LineChart className="w-full" title="Visitors and sign-ups per week" data={DATA} categoryKey="week" series={[{ key: "visitors", label: "Visitors" }, { key: "signups", label: "Sign-ups" }]} />;
}
```
API
- `LineChart`: The chart.
- `data` (`Record<string, string | number>[]`): One row per point in time.
- `categoryKey` (`string`): Key of the time label in each row.
- `series` (`{ key, label }[]`): The lines to draw, up to five.
- `area` (`boolean`, default false): Fill under each line.
- `curve` (`"linear" | "smooth" | "step"`, default "linear"): How points are joined.
- `dots` (`boolean`, default false): Draw a dot on every point.
- `title` (`string`): What the chart shows.
- `formatValue` (`(value: number) => string`): Formats axis and tooltip values.
Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: A hidden table carries the same data for screen readers, and text is never colored by its series. Two or more series always get a legend.
Done when the component renders like the example in light and dark mode and the project type-checks.Usage
import { LineChart } from "@/components/ui/line-chart";
const DATA = [
{ week: "W36", visitors: 4200, signups: 310 },
{ week: "W37", visitors: 4800, signups: 380 },
{ week: "W38", visitors: 4500, signups: 350 },
{ week: "W39", visitors: 5600, signups: 520 },
{ week: "W40", visitors: 6100, signups: 640 },
{ week: "W41", visitors: 5800, signups: 610 },
{ week: "W42", visitors: 7200, signups: 880 },
{ week: "W43", visitors: 7900, signups: 1040 },
];
export default function LineChartDefault() {
return <LineChart className="w-full" title="Visitors and sign-ups per week" data={DATA} categoryKey="week" series={[{ key: "visitors", label: "Visitors" }, { key: "signups", label: "Sign-ups" }]} />;
}Examples
Area
| day | Portfolio |
|---|---|
| Nov 1 | $12k |
| Nov 2 | $12k |
| Nov 3 | $13k |
| Nov 4 | $13k |
| Nov 5 | $13k |
| Nov 6 | $14k |
| Nov 7 | $15k |
| Nov 8 | $14k |
| Nov 9 | $15k |
| Nov 10 | $16k |
| Nov 11 | $16k |
| Nov 12 | $16k |
Smooth area
| week | Active users |
|---|---|
| W1 | 212 |
| W2 | 240 |
| W3 | 228 |
| W4 | 265 |
| W5 | 301 |
| W6 | 289 |
| W7 | 334 |
| W8 | 352 |
| W9 | 341 |
| W10 | 378 |
| W11 | 402 |
| W12 | 419 |
Smooth, two series
- Income
- Spending
| month | Income | Spending |
|---|---|---|
| Jan | $4.2k | $3.1k |
| Feb | $4.2k | $3.4k |
| Mar | $4.9k | $3.0k |
| Apr | $4.2k | $3.8k |
| May | $5.1k | $3.2k |
| Jun | $4.2k | $2.9k |
Step with dots
A value holds until the next change.
| month | Seats |
|---|---|
| Jan | 12 |
| Feb | 12 |
| Mar | 18 |
| Apr | 18 |
| May | 18 |
| Jun | 25 |
| Jul | 25 |
| Aug | 31 |
Dots on every point
- Desktop
- Mobile
| day | Desktop | Mobile |
|---|---|---|
| Mon | 186 | 80 |
| Tue | 305 | 200 |
| Wed | 237 | 120 |
| Thu | 273 | 190 |
| Fri | 209 | 130 |
| Sat | 114 | 140 |
Props
LineChart
The chart.
| Prop | Type | Default | Description |
|---|---|---|---|
| data | Record<string, string | number>[] | – | One row per point in time. |
| categoryKey | string | – | Key of the time label in each row. |
| series | { key, label }[] | – | The lines to draw, up to five. |
| area | boolean | false | Fill under each line. |
| curve | "linear" | "smooth" | "step" | "linear" | How points are joined. |
| dots | boolean | false | Draw a dot on every point. |
| title | string | – | What the chart shows. |
| formatValue | (value: number) => string | – | Formats axis and tooltip values. |
Accessibility
A hidden table carries the same data for screen readers, and text is never colored by its series. Two or more series always get a legend.
Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.