Skip to main content

Legend (S2)

The Legend component in the S2 package supports all props from the base Legend component, including align for controlling legend alignment along its edge.

import { Chart, Axis, Line, Legend } from '@spectrum-charts/react-spectrum-charts-s2';

Legend alignment

The align prop controls where the legend is anchored along its edge — start, middle, or end. The meaning of each value depends on the legend's position:

positionalign: 'start'align: 'middle'align: 'end'
'bottom' / 'top'left-alignedcentered (default)right-aligned
'left' / 'right'top-alignedcentered (default)bottom-aligned
<Chart data={data}>
<Axis position="bottom" labelFormat="time" />
<Axis position="left" grid />
<Line color="series" />
<Legend position="bottom" align="start" title="Operating system" />
</Chart>

Props

PropTypeDefaultDescription
align'start' | 'middle' | 'end''middle'Alignment of the legend along its edge. For horizontal legends (bottom/top): 'start' = left, 'middle' = center, 'end' = right. For vertical legends (left/right): 'start' = top, 'middle' = center, 'end' = bottom.

Hidden series indicator (S2)

S2 uses a different visual pattern for hidden series than S1.

S1S2
Color swatchGrayed to gray-300Shape swapped to VisibilityOff icon, colored to match the label
LabelGrayed to gray-500Stays at full opacity (gray-700)
Visual indicatorColor change onlySwatch shape swap to the VisibilityOff icon path

This applies when isToggleable is true (user-controlled) or when series are hidden via the controlled hiddenSeries prop on <Chart>.

// Toggleable — clicking a legend entry shows the eye icon
<Chart data={data}>
<Line color="series" />
<Legend isToggleable />
</Chart>

The icon is rendered as a native Vega symbol shape (a conditional shape encoding on the legend's symbol mark), not a separate DOM overlay, so it repositions and scales with the chart automatically — no extra resize handling is needed.