Skip to content
EspañolEnglish
All components (204)

Bar chart

Data · BarChart · .amset-bars

What it is and when to use it

The bars of a dashboard: sales by category, orders per day, visits per channel. The drawing is the decoration and the table is the data: below it there is a real table, hidden from view unless requested.

When to use it

  • To compare quantities across a few categories (3 to 12) at a glance.
  • orientation="rows" when the names are long; tableVisible when the exact number matters as much as the shape.
  • max so that two charts that are compared share the same scale.
  • format to write the values (euros, units); without it, numbers in the language of the LocaleProvider. valueName is the header of the values column in the table ("Value" by default).
  • markers for a reference line over the bars (the group average, a target): it crosses all of them at its value and counts toward the axis ceiling and the table.
  • detail on a bar for a second figure shown next to its number ("+8 pts"); only in rows, and in columns it stays in the table.
  • tone colors the bars; axes and values remove or add the axis and the figures.

When not to

  • For change over time, with many points: Trend.
  • For the parts of a total: DonutChart.
  • For a single figure with its change: Stat.

Keyboard: none: there is nothing to press.

Accessibility: the drawing is an image (role="img") with the written summary ("5 bars, total 7810 €. The highest, Rings with 3240 €. The lowest, Watches with 310 €") and the table, with row and column headers, is always there for the screen reader. They are boxes with a percentage height, not an SVG: they print and zoom without distortion. The axis rises to the round number above the largest value.

Fine-tuning: CSS variables --amset-bars-*: -axis, -bar, -cap, -figure-slot, -footer, -gap, -height, -label, -name (what the name takes in rows), -thickness. The size changes the height of the drawing (8, 11.25 or 15 rem), the thickness of the bar and the axis; height still wins if it is passed.

What it looks like

Orders per month
ItemValue
July82
August51
September118

<BarChart
  label="Orders per month"
  data={[
    { key: 'jul', label: 'July', value: 82 },
    { key: 'sep', label: 'September', value: 118, tone: 'success' },
  ]}
/>

Props

Import it with import { BarChart } from '@amset/ui'. Required props are marked.

PropTypeWhat it does
datarequiredreadonly DataBar[]—
labelrequiredstringWhat is being compared. Required: a chart without a title does not inform.
axesbooleanBackground lines with their number.
classNamestringMerged with the library classes; it does not replace them.
format(value: number) => string—
heightnumberHeight of the drawing when they are columns.
markersreadonly BarMarker[]Reference lines over the bars (the average, a target): they count toward the axis ceiling and appear in the table.
maxnumberManual ceiling of the axis, to compare two charts with the same scale.
orientation"rows" | "columns"`columns` rises from the floor; `rows` grows sideways.
size"sm" | "md" | "lg"—
tableVisiblebooleanAlso shows the table. For the screen reader it is always there.
tone"neutral" | "accent" | "secondary" | "tertiary" | "info" | "success" | "warning" | "error"The series color, from the common vocabulary (`neutral` for the secondary one).
valueNamestringWhat the values column is called in the table.
valuesbooleanThe number on top of (or at the end of) each bar.

It also accepts the attributes of the element it renders: className, style, data-*, aria-* and its events.

CSS variables

These CSS variables are how you adapt it. Declare them on the component's selector, not on :root: the stylesheet redeclares them in the rule itself, and a declaration on the same element always wins.

VariableDefault
--amset-bars-axis3rem
--amset-bars-footer1.5rem
--amset-bars-cap1.25rem
--amset-bars-height11.25rem
--amset-bars-bar3.5rem
--amset-bars-thickness0.875rem
--amset-bars-gapvar(--amset-space-2)
--amset-bars-figure-slot3.5rem
--amset-bars-labelvar(--amset-text-xs)
--amset-bars-name8rem
--amset-bars-row-gapvar(--amset-space-3)

How to change it

.amset-bars {
  --amset-bars-axis: ...;
  --amset-bars-footer: ...;
}

In the test bench

Every state and variant, to try one at a time, on its page at ui.amset.tech: