BarChart

A grouped or stacked bar chart over discrete categories.

Import

import { BarChart } from '@matix/charts/bar-chart';

Usage

Data for Revenue
CategoryRevenue values
Jan:12,000.
Feb:18,500.
Mar:9,400.
Apr:21,000.
May:16,200.

Grouped series

Multiple series render side by side within each category by default.

Data for Plan, Actual
CategoryPlan valuesActual values
Q1:40.38.
Q2:45.47.
Q3:50.44.
Q4:55.60.

Fills

fill controls how bars are painted: solid (default) is the plain series color, light outlines each bar in the series color over a one-shade-lighter fill, and gradient adds a subtle opaque diagonal gradient behind the same outline.

Data for Sales
CategorySales values
Jan:24.
Feb:31.
Mar:19.
Apr:36.

Stacked

Set stacked to accumulate series per category instead of grouping them.

Data for Organic, Paid
CategoryOrganic valuesPaid values
Mon:12.8.
Tue:15.6.
Wed:10.9.
Thu:18.7.
Fri:14.11.

Horizontal orientation

Set orientation to 'horizontal' to grow bars rightward from a left category axis instead of upward from a bottom one — useful for long category labels or ranked lists.

Data for Headcount
CategoryHeadcount values
Support:12.
Sales:18.
Engineering:34.
Marketing:9.

Grouped, stacked, and all fill/animation behavior work the same in either orientation.

Value labels and bar shape

showValueLabels writes each value at the end of its bar. Stacked bars show the total of the stack. The chart keeps space for the labels, and formatters.value formats them with location: 'label'. barRadius sets the corner radius of the value end. maxBarSize caps the bar thickness, so that few bars do not fill a wide band.

Data for Visitors
CategoryVisitors values
Direct:12,840.
Search:18,420.
Social:9,630.
Referral:5,210.
Email:2,970.

API Reference

PropTypeDefaultDescription
categoriesreadonly string[]—Category labels; dense axes thin and truncate ticks deterministically
seriesreadonly BarSeries[]—Bar series; data aligns index-by-index with categories
widthnumber—Controlled layout width; enables deterministic SSR
initialWidthnumber—SSR width hint replaced by client measurement
heightnumber280SVG height in px — width is measured from the container
stackedbooleanfalseStack series per category instead of grouping them
orientation'vertical' | 'horizontal''vertical'Grow bars rightward from a left category axis instead of upward from a bottom one
fill'solid' | 'light' | 'gradient''solid'Bar paint: plain color, outlined light fill, or subtle diagonal gradient
showXAxisbooleantrueShow the bottom axis
showYAxisbooleantrueShow the left axis
showGridbooleantrueShow gridlines along the value axis
showTooltipbooleantrueShow the hover tooltip
showLegendbooleantrueShow the legend when there are 2+ series
animatebooleantrueBars grow from the zero baseline, staggered by category
barRadiusnumber3Corner radius in px of the value end of each bar
maxBarSizenumber—Largest bar thickness in px; a thinner bar stays centred in its band
showValueLabelsbooleanfalseWrite each value (or stack total) at the end of its bar
yDomainreadonly [number, number]—Override the computed value-axis extent (x when orientation is 'horizontal')
formattersChartFormatters—Format values, category ticks, legends, tooltips, and accessible data
labelstring—Accessible name; defaults to the joined series labels
labelsChartLabels—Screen-reader text of the data table and the legend, for translation
showLabelbooleanfalseRender label as a visible title above the plot
sxStyleXStyles—StyleX style override

BarSeries

FieldTypeDescription
idstringStable data identity
labelstringLegend / tooltip label, falls back to id
colorIndexnumberPalette slot 0–7; defaults to input order
datareadonly (number | null)[]Finite values aligned with categories; null renders no bar

Series arrays must match categories.length. Development builds warn with the series id and first invalid index; non-finite values do not render.

Accessibility

  • label provides the concise image name. description adds a richer summary through aria-describedby; consumer-owned text or a visible table can be linked with the aria-describedby prop.
  • Categorical datasets up to 20 rows / 100 cells receive a visually hidden native data table. accessibleData replaces that table with custom React content; pass null to suppress it. labels translates the table text and the legend name.
  • Axis, grid, and mark elements remain aria-hidden; the chart is one image target and the table carries category and series values.
  • The pointer tooltip is supplemental; the hidden or consumer-provided data representation carries its values for assistive technology.

Server rendering

Pass width for deterministic server-rendered SVG. Use initialWidth for responsive hydration from a server estimate. Without either prop, the wrapper reserves height before client measurement.