UI

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

Active minutes

Active minutes
DayActive minutes
Tue, Sep 1546
Wed, Sep 1658
Thu, Sep 1724
Fri, Sep 1841
Sat, Sep 1986
Sun, Sep 2067
Today, Sep 2118
Loading interactive preview…

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.

Signups by channel

Signups by channel
CategoryOrganicPaidReferral
Jan32021090
Feb340260110
Mar390240130
Apr410280120
May450300150
Jun470290170
Signups by channel

Signups by channel
CategoryOrganicPaidReferral
Jan32021090
Feb340260110
Mar390240130
Apr410280120
May450300150
Jun470290170

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.

Tickets by team

Tickets by team
CategoryTickets
Billing48
Onboarding31
Integrations57
Security12

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.

ArgumentType / defaultDescription
titlestringDefault: "Bar chart"Figure title. It names the chart for assistive technology and captions the data table.
descriptionstring—One or two sentences on what the chart shows, below the title; omit it when the title says enough.
tableTogglebooleanDefault: falseShow a button that reveals the data table. The table is always available to assistive technology.
tableLabelstringDefault: "Data table"Name of the data table button.
pointLabelstringDefault: "{series}, {x}: {value}"Announced when keyboard focus moves to a bar. {series}, {x} (the category) and {value} are filled in.
noDataLabelstringDefault: "No data"Shown in the tooltip and announced for a category without a value (null).
valueFormatNumberFormat—How values appear in the tooltip, table and axis: decimal, percent or currency, with fraction digits. Axis ticks are compacted (12.9K).
localestring—BCP 47 locale for numbers. Omit it to inherit the application locale (en-US by default).
categoriesChartCategory[]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.
seriesChartCategorySeries[]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.
categoryLabelstringDefault: "Category"Header of the category column in the data table.
layoutgrouped | stackedDefault: "grouped"grouped places series side by side in each category; stacked adds them into one bar (values must be zero or more).
orientationvertical | horizontalDefault: "vertical"vertical draws columns rising from the baseline; horizontal draws bars from the inline start, for many or long category names.
showAveragebooleanDefault: trueDraw the average of the shown bars as a dashed line, labeled in the value gutter.
showAverageSummarybooleanDefault: trueShow 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.
averageTickLabelstringDefault: "Avg {value}"Label of the average line in the value gutter. {value} is filled in.
periodstring—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).
unitstring—Unit after the headline value, such as "min".
averageLabelstringDefault: "Average"Headline label at rest, above the average.
valueLabelstringDefault: "Total"Headline label while a bar is explored.
exploreLabelstringDefault: "{title}, explore by {category}"Accessible name of the scrubber over the plot. {title} and {category} (categoryLabel, lowercased) are filled in.
scrubLabelstringDefault: "{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.
highestLabelstringDefault: "Highest {label}, {value}"Sentence for the highest bar in the chart summary. {label} and {value} are filled in.
lowestLabelstringDefault: "Lowest {label}, {value}"Sentence for the lowest bar in the chart summary. {label} and {value} are filled in.
legendTogglebooleanDefault: trueWith two or more series, legend entries hide and show their series.
legendLabelstringDefault: "Legend"Accessible name of the legend list.
heightintegerDefault: 202Total height in pixels, axes included (120–640). The default is a 176 pixel plot over a 26 pixel axis.
recipestudio | softDefault: "studio"Visual treatment. Both recipes use the same interaction behavior.
themeBarChartTheme—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.
motionnone | subtle | expressiveDefault: "subtle"Draw-in and data change animation preset. System reduced-motion preferences take precedence.
motionOptionsChartMotionOptions—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.
dirltr | 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

PropPurpose
presetApplication defaults, overridden by explicit instance props
tokensCSS variables applied after the typed theme
refRef forwarded to the root <figure>
className, styleApplied to the root <figure>
Native attributesid, data-*, and remaining <figure> attributes forwarded to the root

Keyboard & accessibility

KeyInteraction
TabFocus the plot scrubber, legend buttons, and table
ArrowLeft, DownStep backward one category
ArrowRight, UpStep forward one category (starts at latest)
PageUp, PageDownJump seven categories
Home, EndJump to the first or last category
EscapeClear 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": []
}

On this page