Bar chart
Compares one to eight series across categories, grouped or stacked, as vertical columns or horizontal bars.
import { BarChart } from '@uthereal/ui/bar-chart'Bar chart playground
| Day | Active minutes |
|---|---|
| Tue, Sep 15 | 46 |
| Wed, Sep 16 | 58 |
| Thu, Sep 17 | 24 |
| Fri, Sep 18 | 41 |
| Sat, Sep 19 | 86 |
| Sun, Sep 20 | 67 |
| Today, Sep 21 | 18 |
Overview
A bar chart compares values across discrete categories such as quarters, teams, or channels. Each category renders one bar per series (grouped) or one segmented bar (stacked), oriented as vertical columns (vertical) or horizontal bars (horizontal). A dashed reference line marks the average of visible bars. Single-series charts (or charts with a period) render a headline readout; multi-series charts render a legend and floating tooltip. A data table carries every value.
Use one series for a single measure and multiple series only when comparing across categories. Beyond eight series, fold smaller entries into an "Other" series. For one value against a known range, use a gauge. For continuous time series, use a line chart. For exact multi-column records, use a data grid.
Usage
import { BarChart } from '@uthereal/ui/bar-chart'
export function Revenue() {
return (
<BarChart
title="Revenue by quarter"
valueFormat={{ style: 'currency', currency: 'USD' }}
categories={[
{ id: 'q1', label: 'Q1' },
{ id: 'q2', label: 'Q2' },
]}
series={[{ id: 'revenue', label: 'Revenue', values: [42000, 51000] }]}
/>
)
}Supply one value per category in each series, in category order. Pass null for missing values; missing entries display as "No data" rather than zero. Use axisLabel on a category for a compact tick label while keeping label for the readout and data table.
Examples
Grouped and stacked
grouped (default) places series side by side per category. stacked sums series into a single bar with a 2 px surface gap between segments and a rounded cap on the top segment. Stacked series require values of zero or more.
| Category | Organic | Paid | Referral |
|---|---|---|---|
| Jan | 320 | 210 | 90 |
| Feb | 340 | 260 | 110 |
| Mar | 390 | 240 | 130 |
| Apr | 410 | 280 | 120 |
| May | 450 | 300 | 150 |
| Jun | 470 | 290 | 170 |
| Category | Organic | Paid | Referral |
|---|---|---|---|
| Jan | 320 | 210 | 90 |
| Feb | 340 | 260 | 110 |
| Mar | 390 | 240 | 130 |
| Apr | 410 | 280 | 120 |
| May | 450 | 300 | 150 |
| Jun | 470 | 290 | 170 |
Horizontal bars
Set orientation: 'horizontal' to draw bars from the inline start with category labels beside them. Use horizontal orientation when category names are long or numerous.
| Category | Tickets |
|---|---|
| Billing | 48 |
| Onboarding | 31 |
| Integrations | 57 |
| Security | 12 |
Behavior
Bars occupy 58% of their slot up to 28 px thick, with a 4 px rounded data end and a square baseline at zero; negative values extend in the opposite direction. The value axis sits in a 52 px gutter at the inline end, starts at zero, and draws up to four grid rows on clean steps (1, 2, 3, or 5) with compact labels. showAverage (default true) renders a dashed average line labeled averageTickLabel in the gutter. Set showAverageSummary: false to hide the average headline and use per-bar tooltips instead.
A single series uses a tinted step of the theme accent (62% over surface in light mode, 76% in dark mode). Exploring a bar elevates it to full accent while dimming remaining bars. Multi-series charts assign each series a stable palette color (series1–series8) or its own color; legend buttons toggle series visibility without repainting remaining series, and the last visible series cannot be hidden. Touch and pen drags scrub categories while vertical swipes scroll the page.
API reference
These serializable arguments and defaults come directly from the component schema.
| Argument | Type / default | Description |
|---|---|---|
title | stringDefault: "Bar chart" | Figure title. It names the chart for assistive technology and captions the data table. |
description | string— | One or two sentences on what the chart shows, below the title; omit it when the title says enough. |
tableToggle | booleanDefault: false | Show a button that reveals the data table. The table is always available to assistive technology. |
tableLabel | stringDefault: "Data table" | Name of the data table button. |
pointLabel | stringDefault: "{series}, {x}: {value}" | Announced when keyboard focus moves to a bar. {series}, {x} (the category) and {value} are filled in. |
noDataLabel | stringDefault: "No data" | Shown in the tooltip and announced for a category without a value (null). |
valueFormat | NumberFormat— | How values appear in the tooltip, table and axis: decimal, percent or currency, with fraction digits. Axis ticks are compacted (12.9K). |
locale | string— | BCP 47 locale for numbers. Omit it to inherit the application locale (en-US by default). |
categories | ChartCategory[]Default: [{"id":"q1","label":"Q1"},{"id":"q2","label":"Q2"},{"id":"q3","label":"Q3"},{"id":"q4","label":"Q4"}] | The categories along the category axis, in order: an id and a label each. At most 200. |
series | ChartCategorySeries[]Default: [{"id":"revenue","label":"Revenue","values":[12,18,15,21]}] | One to eight series, each with an id, a label, one value per category (null for no data) and an optional own color. Colors follow the series order (or the own color) and never move when a series is hidden. |
categoryLabel | stringDefault: "Category" | Header of the category column in the data table. |
layout | grouped | stackedDefault: "grouped" | grouped places series side by side in each category; stacked adds them into one bar (values must be zero or more). |
orientation | vertical | horizontalDefault: "vertical" | vertical draws columns rising from the baseline; horizontal draws bars from the inline start, for many or long category names. |
showAverage | booleanDefault: true | Draw the average of the shown bars as a dashed line, labeled in the value gutter. |
showAverageSummary | booleanDefault: true | Show the average headline and accessible average summary. Disable to keep the chart title and individual bar tooltips without an aggregate average; showAverage controls the reference line separately. |
averageTickLabel | stringDefault: "Avg {value}" | Label of the average line in the value gutter. {value} is filled in. |
period | string— | The range on show, such as "Sep 15–21". Set it to show the headline readout above the plot: the average at rest, the explored bar while hovering or focusing (it replaces the tooltip). |
unit | string— | Unit after the headline value, such as "min". |
averageLabel | stringDefault: "Average" | Headline label at rest, above the average. |
valueLabel | stringDefault: "Total" | Headline label while a bar is explored. |
exploreLabel | stringDefault: "{title}, explore by {category}" | Accessible name of the scrubber over the plot. {title} and {category} (categoryLabel, lowercased) are filled in. |
scrubLabel | stringDefault: "{x}: {value}" | Value text of the scrubber with one series, e.g. "Tue, Sep 15: 46 min". {x} and {value} (with the unit) are filled in. |
highestLabel | stringDefault: "Highest {label}, {value}" | Sentence for the highest bar in the chart summary. {label} and {value} are filled in. |
lowestLabel | stringDefault: "Lowest {label}, {value}" | Sentence for the lowest bar in the chart summary. {label} and {value} are filled in. |
legendToggle | booleanDefault: true | With two or more series, legend entries hide and show their series. |
legendLabel | stringDefault: "Legend" | Accessible name of the legend list. |
height | integerDefault: 202 | Total height in pixels, axes included (120–640). The default is a 176 pixel plot over a 26 pixel axis. |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes use the same interaction behavior. |
theme | BarChartTheme— | Color mode, accent, and tokens: a single series is drawn in the accent, several in the chart palette (series1–series8); readoutSize sets the headline value. See Theming. |
motion | none | subtle | expressiveDefault: "subtle" | Draw-in and data change animation preset. System reduced-motion preferences take precedence. |
motionOptions | ChartMotionOptions— | draw (bars growing in, staggered, when the chart scrolls into view) and morph (bars springing to new data; a new set of categories zooms the axis around the latest bar, new bars grow in and leaving bars sink out): a tween with a duration (ms) or a spring. |
dir | ltr | rtl— | Reading direction. rtl mirrors the category order of columns and the value axis of horizontal bars. Omit it to inherit the page direction. |
React integration
| Prop | Purpose |
|---|---|
preset | Application defaults, overridden by explicit instance props |
tokens | CSS variables applied after the typed theme |
ref | Ref forwarded to the root <figure> |
className, style | Applied to the root <figure> |
| Native attributes | id, data-*, and remaining <figure> attributes forwarded to the root |
Keyboard & accessibility
| Key | Interaction |
|---|---|
Tab | Focus the plot scrubber, legend buttons, and table |
ArrowLeft, Down | Step backward one category |
ArrowRight, Up | Step forward one category (starts at latest) |
PageUp, PageDown | Jump seven categories |
Home, End | Jump to the first or last category |
Escape | Clear the active bar and readout |
The chart renders a <figure> named by title and described by description. aria-details links to a native data table with categories as row headers and series as columns; set tableToggle: true to expose a visible toggle button. The SVG plot is hidden from assistive technology.
A single role="slider" scrubber named by exploreLabel covers the plot. Its aria-valuetext uses scrubLabel for a single series or pointLabel per series. An accessible summary names the title, period, average, highestLabel, and lowestLabel, and category set updates are announced once. Text never relies on series color alone. In RTL, category order mirrors across the inline axis. Under forced-colors, system colors apply.
Motion and theming
Bars grow from the baseline once when the chart scrolls into view, staggered by 35 ms (capped at 360 ms total), followed by the average line; server-rendered markup is final. subtle draws over 700 ms and expressive draws over 840 ms. Data updates spring each bar on motionOptions.morph, keyed by category; category-set changes zoom around the latest bar while the average line and gridlines track the new scale. Headline values roll digit by digit while labels cross-slide with a subtle blur. motionOptions.draw and motionOptions.morph accept a tween with duration (ms) or a spring. Resizes update immediately. motion="none" and prefers-reduced-motion: reduce disable draw-in and morph transitions.
theme accepts a mode, an accent, and semantic tokens including the chart palette (series1–series8) and readoutSize (36 px). An application-wide UtherealProvider supplies defaults.
Composition
In an agent composition, BarChart is a leaf with no actions. The host updates categories and series through composition updates. See Building with agents.
{
"type": "BarChart",
"props": {
"title": "Tickets by team",
"categories": [
{ "id": "billing", "label": "Billing" },
{ "id": "security", "label": "Security" }
],
"series": [{ "id": "tickets", "label": "Tickets", "values": [48, 12] }]
},
"children": []
}