Components
Bar Chart
NativeCompares amounts across categories, with solid bars or bars built from square dots.
| month | Revenue |
|---|---|
| Jun | $18k |
| Jul | $22k |
| Aug | $20k |
| Sep | $27k |
| Oct | $31k |
| Nov | $30k |
Installation
npx nook-ui@latest add bar-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 "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.
| day | Focus time |
|---|---|
| Mon | 5.5h |
| Tue | 6.5h |
| Wed | 4h |
| Thu | 7.5h |
| Fri | 6h |
| Sat | 2h |
| Sun | 1h |
Two series
Two or more series get a legend.
- Web
- Mobile
| quarter | Web | Mobile |
|---|---|---|
| Q1 | 420 | 310 |
| Q2 | 480 | 390 |
| Q3 | 510 | 470 |
| Q4 | 560 | 610 |
With values
| day | Orders |
|---|---|
| Mon | 42 |
| Tue | 58 |
| Wed | 51 |
| Thu | 73 |
| Fri | 96 |
| Sat | 120 |
| Sun | 64 |
One bar highlighted
| month | Sign-ups |
|---|---|
| Jun | 310 |
| Jul | 280 |
| Aug | 340 |
| Sep | 520 |
| Oct | 410 |
| Nov | 450 |
Horizontal
Long category names read left to right.
| channel | Visits |
|---|---|
| Search | 48.2K |
| Newsletter | 31.9K |
| Direct | 24.1K |
| Social | 15.6K |
| Referrals | 9.8K |
Horizontal, two series
- Planned
- Done
| team | Planned | Done |
|---|---|---|
| Design | 120h | 96h |
| Engineering | 340h | 288h |
| Support | 160h | 171h |
| Marketing | 90h | 52h |
Variants
Defined in one place with cva, at the top of the component file.
variant
solid (default)dots
Props
BarChart
The chart.
| Prop | Type | Default | Description |
|---|---|---|---|
| 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" | "vertical" | Horizontal lists categories down the side, good for long names and rankings. |
| showValues | boolean | false | Print each value at the end of its bar. |
| highlight | string | – | A category to emphasise. The other bars are dimmed. |
| cells | number | 10 | Cells 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.