BarChart
A grouped or stacked bar chart over discrete categories.
Import
import { BarChart } from '@matix/charts/bar-chart';Usage
| Category | Revenue 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.
| Category | Plan values | Actual 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.
| Category | Sales values |
|---|---|
| Jan: | 24. |
| Feb: | 31. |
| Mar: | 19. |
| Apr: | 36. |
Stacked
Set stacked to accumulate series per category instead of grouping them.
| Category | Organic values | Paid 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.
| Category | Headcount 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.
| Category | Visitors values |
|---|---|
| Direct: | 12,840. |
| Search: | 18,420. |
| Social: | 9,630. |
| Referral: | 5,210. |
| Email: | 2,970. |
API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
categories | readonly string[] | — | Category labels; dense axes thin and truncate ticks deterministically |
series | readonly BarSeries[] | — | Bar series; data aligns index-by-index with categories |
width | number | — | Controlled layout width; enables deterministic SSR |
initialWidth | number | — | SSR width hint replaced by client measurement |
height | number | 280 | SVG height in px — width is measured from the container |
stacked | boolean | false | Stack 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 |
showXAxis | boolean | true | Show the bottom axis |
showYAxis | boolean | true | Show the left axis |
showGrid | boolean | true | Show gridlines along the value axis |
showTooltip | boolean | true | Show the hover tooltip |
showLegend | boolean | true | Show the legend when there are 2+ series |
animate | boolean | true | Bars grow from the zero baseline, staggered by category |
barRadius | number | 3 | Corner radius in px of the value end of each bar |
maxBarSize | number | — | Largest bar thickness in px; a thinner bar stays centred in its band |
showValueLabels | boolean | false | Write each value (or stack total) at the end of its bar |
yDomain | readonly [number, number] | — | Override the computed value-axis extent (x when orientation is 'horizontal') |
formatters | ChartFormatters | — | Format values, category ticks, legends, tooltips, and accessible data |
label | string | — | Accessible name; defaults to the joined series labels |
labels | ChartLabels | — | Screen-reader text of the data table and the legend, for translation |
showLabel | boolean | false | Render label as a visible title above the plot |
sx | StyleXStyles | — | StyleX style override |
BarSeries
| Field | Type | Description |
|---|---|---|
id | string | Stable data identity |
label | string | Legend / tooltip label, falls back to id |
colorIndex | number | Palette slot 0–7; defaults to input order |
data | readonly (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
labelprovides the concise image name.descriptionadds a richer summary througharia-describedby; consumer-owned text or a visible table can be linked with thearia-describedbyprop.- Categorical datasets up to 20 rows / 100 cells receive a visually hidden native data table.
accessibleDatareplaces that table with custom React content; passnullto suppress it.labelstranslates 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.