Skip to content
Haze UI

Bar chart

Inspect signed columns against their arithmetic mean with a value readout, pointer and keyboard scrubbing, and an exact data table.

pnpm dlx shadcn@latest add @haze/bar-chart
Open preview in a new tab
Livesmall script

When to use

  • A report compares one measurement across distinct periods or categories.
  • The mean gives readers a reference point for individual counts.

When not to use

  • Several series share the same time axis. Use line-chart.
  • Long category names need to appear alongside horizontal bars. Use bar-list.

Installation

Add the Haze registry to components.json once, then install Bar chart with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/bar-chart
First time? Registry and theme setup

1. Add to components.json:

{
  "registries": {
    "@haze": "http://localhost:4329/r/{name}.json"
  }
}

2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";

API reference

PropTypeDefaultDescription
labelstringMerged pull requestsName of the measure and the caption of the data table.
data{ label: string; value: number }[]–Finite positive, negative or zero values in display order. Nonfinite entries are excluded.
unitstringempty stringSuffix on the headline and table values.
categoryLabelstringDayName of the categories in the table and scrubber.
averageLabelstringDaily averageName of the reference line and resting value.
showAveragebooleantrueDraw the dashed mean line and its legend.
detailsLabelstringView dataDisclosure label for the original category values.
emptyLabelstring–Message when there are no finite categories to compare.
classstring–Additional classes on the chart figure.

Keyboard interactions

Arrow keys
Move between the mean and individual columns.
HomeEscape
Return to the arithmetic mean.
End
Inspect the last column.
EnterSpace
Open or close the focused data disclosure.

Accessibility

  • The native range control announces each category and amount. Opening the data table also works with JavaScript disabled.
  • The dashed reference line has a textual legend. Reduced motion shows the finished columns immediately.

Notes for AI

Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.

  • Install and use

    Install the Haze UI component "Bar chart" with `npx shadcn@latest add @haze/bar-chart`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import BarChart from "@/components/haze/ui/bar-chart.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/bar-chart.md

  • Customize with real content

    Adapt the Haze bar-chart ui for our product. Replace the demo values of these props with our real content: label, data, unit, categoryLabel, averageLabel, showAverage, detailsLabel, emptyLabel, class. Keep the layout, the heading level rules and these accessibility details: The native range control announces each category and amount. Opening the data table also works with JavaScript disabled. The dashed reference line has a textual legend. Reduced motion shows the finished columns immediately. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using bar-chart, check it fits: use it when a report compares one measurement across distinct periods or categories.; the mean gives readers a reference point for individual counts.. Avoid it when several series share the same time axis. use line-chart.; long category names need to appear alongside horizontal bars. use bar-list.. Alternatives: @haze/bar-list, @haze/line-chart, @haze/bento-growth.

Dependencies

  • @haze/collapsible
  • @haze/table
  • @haze/utils
  • @haze/theme (one-time setup)

Source · Original Haze UI work.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog