nook
Browse the docs

Components

Bar Chart

Native

Compares amounts across categories, with solid bars or bars built from square dots.

See the prompt
Revenue per month
Revenue per month
monthRevenue
Jun$18k
Jul$22k
Aug$20k
Sep$27k
Oct$31k
Nov$30k

Installation

npx nook-ui@latest add bar-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 "Bar Chart" component to this project, exactly as Nook ships it.

Compares amounts across categories, with solid bars or bars built from square dots.

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 bar-chart`. It writes `components/ui/bar-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/bar-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 { BarChart } from "@/components/ui/bar-chart";

const DATA = [
  { month: "Jun", revenue: 18400 },
  { month: "Jul", revenue: 22100 },
  { month: "Aug", revenue: 19800 },
  { month: "Sep", revenue: 27300 },
  { month: "Oct", revenue: 31200 },
  { month: "Nov", revenue: 29600 },
];

export default function BarChartDefault() {
  return <BarChart className="w-full" title="Revenue per month" data={DATA} categoryKey="month" series={[{ key: "revenue", label: "Revenue" }]} formatValue={(v) => `$${(v / 1000).toFixed(0)}k`} />;
}
```

API
- `BarChart`: The chart.
  - `data` (`Record<string, string | number>[]`): One row per category.
  - `categoryKey` (`string`): Key of the category name in each row.
  - `series` (`{ key, label }[]`): The values to draw, up to five.
  - `title` (`string`): What the chart shows.
  - `orientation` (`"vertical" | "horizontal"`, default "vertical"): Horizontal lists categories down the side, good for long names and rankings.
  - `showValues` (`boolean`, default false): Print each value at the end of its bar.
  - `highlight` (`string`): A category to emphasise. The other bars are dimmed.
  - `cells` (`number`, default 10): Cells per bar in the dots variant.
  - `formatValue` (`(value: number) => string`): Formats axis and tooltip values.
- Variant `variant`: solid, dots (default solid)

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. Hover shows the exact values.

Done when the component renders like the example in light and dark mode and the project type-checks.

Usage

import { BarChart } from "@/components/ui/bar-chart";

const DATA = [
  { month: "Jun", revenue: 18400 },
  { month: "Jul", revenue: 22100 },
  { month: "Aug", revenue: 19800 },
  { month: "Sep", revenue: 27300 },
  { month: "Oct", revenue: 31200 },
  { month: "Nov", revenue: 29600 },
];

export default function BarChartDefault() {
  return <BarChart className="w-full" title="Revenue per month" data={DATA} categoryKey="month" series={[{ key: "revenue", label: "Revenue" }]} formatValue={(v) => `$${(v / 1000).toFixed(0)}k`} />;
}

Examples

Square dots

Each bar is a stack of cells, so amounts can be counted.

Focus time per day
Focus time per day
dayFocus time
Mon5.5h
Tue6.5h
Wed4h
Thu7.5h
Fri6h
Sat2h
Sun1h

Two series

Two or more series get a legend.

Sign-ups per quarter by platform
  • Web
  • Mobile
Sign-ups per quarter by platform
quarterWebMobile
Q1420310
Q2480390
Q3510470
Q4560610

With values

Orders per weekday
Orders per weekday
dayOrders
Mon42
Tue58
Wed51
Thu73
Fri96
Sat120
Sun64

One bar highlighted

Sign-ups per month, with the launch month highlighted
Sign-ups per month, with the launch month highlighted
monthSign-ups
Jun310
Jul280
Aug340
Sep520
Oct410
Nov450

Horizontal

Long category names read left to right.

Visits by channel in November
Visits by channel in November
channelVisits
Search48.2K
Newsletter31.9K
Direct24.1K
Social15.6K
Referrals9.8K

Horizontal, two series

Hours planned and done per team
  • Planned
  • Done
Hours planned and done per team
teamPlannedDone
Design120h96h
Engineering340h288h
Support160h171h
Marketing90h52h

Variants

Defined in one place with cva, at the top of the component file.

  • variant

    solid (default)dots

Props

BarChart

The chart.

PropTypeDefaultDescription
dataRecord<string, string | number>[]–One row per category.
categoryKeystring–Key of the category name in each row.
series{ key, label }[]–The values to draw, up to five.
titlestring–What the chart shows.
orientation"vertical" | "horizontal""vertical"Horizontal lists categories down the side, good for long names and rankings.
showValuesbooleanfalsePrint each value at the end of its bar.
highlightstring–A category to emphasise. The other bars are dimmed.
cellsnumber10Cells per bar in the dots variant.
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. Hover shows the exact values.

Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.