Search documentation

Search pages, components, blocks, styles and colours.

Get started
Skip to content

Bar Chart

PreviousNext

Magnitude by category, as bars side by side or stacked, in columns or rows.

Revenue by region
Acme Inc, first half of 2026
Revenue by region
SubscriptionsServicesMarketplace
North America$66K$75K$31K
Europe$102K$61K$36K
Asia Pacific$72K$50K$36K
Latin America$29K$23K$25K
Middle East$51K$16K$13K
Africa$18K$12K$9K

Give it rows of data, the field that names each category (index) and a config that names the series to draw. Each category gets a bar per series, side by side, in the next colour of the chart palette. Bars are at most 24px thick, so the rest of each band is air; they grow from zero with a rounded end and a square base, and bars that touch keep a 2px gap.

Point at a category, drag a finger across the chart or tab to it and use the arrow keys: a soft highlight glides to the category and a tooltip lists its series. The legend hides a series when pressed and spotlights it when pointed at. Bars grow in a quick wave the first time the chart is on screen, and move to their new size and place when the data changes.

Bar Chart is part of the Fabricator style. It's drawn in SVG, so the same component ships for every base, and its layout comes from the same model as the React Native version.

Installation

bunx --bun fabricator-ui@latest add bar-chart

Usage

import { BarChart } from "@/components/ui/bar-chart"
import { type ChartConfig } from "@/components/ui/chart-kit"
const data = [
  { region: "Europe", subscriptions: 102_000, services: 61_000 },
  { region: "Asia Pacific", subscriptions: 72_000, services: 50_000 },
]
 
const config = {
  subscriptions: { label: "Subscriptions" },
  services: { label: "Services" },
} satisfies ChartConfig
 
<BarChart data={data} index="region" config={config} label="Revenue by region" />

Negative values grow down from zero. A missing value leaves its bar out. The chart fills its container's width and is 18rem tall until you give it a height with className.

Values print in full (1,234) until you pass formatValue. It also formats the hidden table, which renders on the server, so use a formatter that writes the same text in Node and in the browser: formatChartNumber(value, { compact: true }) from lib/chart-model gives 43.9K on both, where Intl's compact notation can differ between them.

Examples

Stacked

stack="stacked" sets each series on the ones before it, so the column is the category's total. Only the outer end of each column is rounded, and segments keep a 2px gap.

Support tickets by state
ResolvedOpenEscalated
Jan182349
Feb2054112
Mar231297
Apr1985215
May2463811
Jun262276

Horizontal

layout="horizontal" lays the categories down the start edge, for long names. A single series needs no legend: label already names what is plotted.

Top pages by visits
Visits
/pricing18,420
/docs/getting-started15,310
/blog/launch-week11,870
/changelog8,240
/integrations6,930
/careers3,160

Changing the data

Bars move to their new place and size when the stacking, the order or the values change, so the eye can follow each one.

Issues shipped and planned by team
ShippedPlanned
Design1824
Platform3128
Growth1220
Mobile2219
Data914

Colours

Series take the chart palette in the order of config, and keep their colour when another is hidden. Give a series its own with color: a palette slot, an upstream chart token (chart-1 … chart-5), a role (primary, info, success, …), a CSS variable (var(--brand)) or any CSS colour.

TokenHueTokenHue
--chart-series-1blue--chart-series-5magenta
--chart-series-2orange--chart-series-6green
--chart-series-3aqua--chart-series-7violet
--chart-series-4amber--chart-series-8red

Colour one series per meaning: categories of a single series share its colour, since the bar's length already shows the value. The palette ships with the foundations, chosen separately for light and dark, every slot at 3:1 or more against the page and the card.

Motion

  • Grow: the first time the chart scrolls into view, bars grow from zero in a quick wave along the categories, on the reveal role, once per mount.
  • Morph: when data, config, stack, layout or the visible series change, each bar moves and resizes on the move role. A series being shown grows from zero; one being hidden shrinks into it.
  • Glide: the category highlight and the tooltip glide between categories on the glide role.

All three follow the motion speed of the region they sit in. Reduce Motion and the instant speed draw the chart at once and drop the glide; animate={false} does the same for one chart.

API Reference

BarChart

All other props go to the root <div>.

PropTypeDefault
dataTDatum[]required
configChartConfigrequired
indexkeyof TDatumrequired
labelstringrequired: the accessible name
layout"vertical" | "horizontal""vertical"
stack"none" | "stacked""none"
formatValue(value: number, key: string) => string1,234
formatIndex(value: string, datum: TDatum) => stringthe field as text
legendbooleanon for two or more series
tooltipbooleantrue
animatebooleantrue
loadingbooleanfalse
emptyReactNode"No data"
onActiveChange(active: ChartActive<TDatum> | null) => void-

ChartConfig

FieldTypeDefault
labelstringrequired
colorChartColorthe next palette slot

Data attributes

AttributeElementPresent when
data-slot="bar-chart"rootalways
data-loadingrootloading is true
data-slot="chart-plot"the plotalways
data-slot="chart-bar"a baralways; data-dimmed while another is spotlit
data-slot="chart-band"highlighta category is inspected
data-slot="chart-legend"the legendthe legend shows
data-slot="chart-tooltip"the tooltipa category is inspected

Accessibility

  • The plot is a slider named after label ("Revenue by region: inspect values"). Tab to it, then the arrow keys step through the categories, Home and End jump to the first and last, and Escape lets go. Its value text reads the tooltip: the category and every series' value.
  • Every value is also in a table hidden from sight, so a screen reader can read the data without inspecting it.
  • With two or more series the legend always shows, so no series is told apart by colour alone. Its items are toggle buttons with aria-pressed.
  • Text never takes a series colour: values and labels stay in the text colours, beside a coloured key.
  • loading sets aria-busy on the root and dims the last drawing until new data arrives.