nook
Browse the docs

Components

Line Chart

Native

Shows change over time as lines or filled areas, with a crosshair that reads every series at once.

See the prompt
Visitors and sign-ups per week
  • Visitors
  • Sign-ups
Visitors and sign-ups per week
weekVisitorsSign-ups
W364.2K310
W374.8K380
W384.5K350
W395.6K520
W406.1K640
W415.8K610
W427.2K880
W437.9K1K

Installation

npx nook-ui@latest add line-chart

Prompt

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.

Plain text
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

Portfolio value in November
Portfolio value in November
dayPortfolio
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

Weekly active users
Weekly active users
weekActive users
W1212
W2240
W3228
W4265
W5301
W6289
W7334
W8352
W9341
W10378
W11402
W12419

Smooth, two series

Income and spending
  • Income
  • Spending
Income and spending
monthIncomeSpending
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.

Paid seats per month
Paid seats per month
monthSeats
Jan12
Feb12
Mar18
Apr18
May18
Jun25
Jul25
Aug31

Dots on every point

Visitors by device
  • Desktop
  • Mobile
Visitors by device
dayDesktopMobile
Mon18680
Tue305200
Wed237120
Thu273190
Fri209130
Sat114140

Props

LineChart

The chart.

PropTypeDefaultDescription
dataRecord<string, string | number>[]–One row per point in time.
categoryKeystring–Key of the time label in each row.
series{ key, label }[]–The lines to draw, up to five.
areabooleanfalseFill under each line.
curve"linear" | "smooth" | "step""linear"How points are joined.
dotsbooleanfalseDraw a dot on every point.
titlestring–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.