Components / data

ChartLegend

Which color is which series.

Rendered from the package · open on its own

Summary

Which color is which series.

APG patternnone
Built onnative elements
Statusself-tested
Since0.16.0
<ChartLegend
  label="Budget groups"
  items={[
    { label: 'Everyday spending', value: '$2,410' },
    { label: 'Calendar costs', value: '$310' },
    { label: 'Yearly set-asides', value: '$375' },
    { label: 'Fixed costs', value: '$3,120', series: 'neutral' },
  ]}
/>

Anatomy

A <ul data-se="chart-legend"> named by its label. Each item is one series: a swatch in the series color, the label, and a value when one is given. The series is written on the item as data-series.

PartElementRequired
item<li>yes
label<span>yes
swatch<span>yes
value<span>no

Properties

PropertyValuesDefaultWhat it does
itemsChartLegendItem[]requiredOne entry per series, in the order the marks are drawn.
labelstringrequiredIts name, such as Series or Budget groups. Not drawn.

States

_None. Rest is the only condition it has._

Behavior

Items take the series colors in order. The first item with no series of its own takes the first color, the second the second, the third the third. Every one after that takes the neutral, as a Chart's series past the third do. The colors never cycle.

A neutral item is the series the others are compared against. It takes the muted text color, which is not a step of the series scale.

The order is the drawing's order. The first item is the first series drawn.

Accessibility

Every swatch has a name. Color is one sign and the name beside it is the other. Roughly one man in twelve cannot tell some pairs of colors apart, and a screen reader cannot tell any, so the swatch is hidden from it and the name is what is read.

It is a list, and it says so. role="list" is written out: a list with its markers removed is not announced as a list by every screen reader.

Keyboard

None of its own. It is not focusable and takes no keys.

Roles, states and properties

AttributeSet by
aria-hiddenalways true
aria-labelset at render
rolealways list

Focus

Never takes focus. It reports and offers no action.

Screen reader

Not recorded as verified. Stage 4 of the readiness ladder — driving each component with VoiceOver and NVDA — is unstarted across the package, and no component should claim otherwise until docs/journal/ records the session that did it.

Contrast and target size

npm run check:contrast audits every color pair this component uses across all four skins, light and dark, and fails the build on a shortfall. Two waivers are on the record in docs/audit/DEFERRED.md.

It sets no target size of its own; anything interactive inside it brings its own.

Each series color is held to 3:1 on --se-surface by check:contrast, and every pair of them, with --se-text-muted, is held apart by check:skins for a reader who cannot separate red from green.

Tested

  • test/apg/chart-legend.test.jsx
  • test/browser/chart-legend.spec.mjs

Known gaps

_No upstream requirement is recorded as not applicable._

Appearance

A row that wraps, a space step between rows and a wider one between items. The swatch is --se-dot-size, the size of the status dot beside a row's meta text, because it is the same thing: a mark beside a word. The name is interface text; the value is semibold with figures that line up.

TokenUsed for
--se-dot-sizeblock-size, inline-size
--se-radius-pillborder-radius
--se-series-1series
--se-series-2series
--se-series-3series
--se-space-2gap
--se-space-4gap
--se-textcolor
--se-text-mutedseries
--se-text-smfont-size
--se-weight-semiboldfont-weight

Motion

Nothing moves.

Content

Use the name the chart's heading and readout use for the same series. One name per series, everywhere.

A value is a figure for the whole series, such as its total. Not the value under the pointer: that is the chart's readout.

Usage

Beside a chart with more than one series, or beside any marks colored by series: a stacked bar, a set of dots.

Not for one series. The heading already names it.

Not for a status. Use Badge.

It goes above its chart, at the top of the card's body, and not in a Header's action: it is not an action.

Notes

Named ChartLegend, not Legend. A legend is already a part: the caption of a group of controls. The compound-name rule puts what sets it apart first.

Three series colors and a neutral, not four. The series scale has three steps (docs/proposals/2026-11-14-series-colors.md). The prototype's fourth color was a gray for the series the others are compared against, and --se-text-muted already names that.

An item cannot be pressed to hide its series. The prototype does not do it. If it could, the item would be a control and this would need a key table; that is an open question in the parent spec.

The swatch's size is --se-dot-size, 8px. The prototype draws 10. The token is the system's name for a dot beside a word, and a second size for the same job would be a second name for it.