A legend is the key to a chart or to any colour-coded view — a status map, a coloured table, a timeline. .legend is a wrapping row of .legend__items; each item is a swatch and a label. The swatches have the shapes and sizes of the legend RareCharts draws inside a chart, so a legend on the page and a legend in a chart read as one.
- Revenue
- Forecast
- Orders
- Plan range
<ul class="legend">
<li class="legend__item">
<span class="legend__swatch legend__swatch--line" style="--swatch-color: #1677ff"></span>
Revenue
</li>
</ul>
Swatches
The colour comes from --swatch-color, set on the swatch, on the item or on the whole legend; without it a swatch takes the text colour. The bare .legend__swatch is a small square; a modifier gives it the shape of the series it names.
.legend__swatch--line- A short rule, for a line series.
.legend__swatch--dashed- A dashed rule, for a forecast or a projected series.
.legend__swatch--dot- A dot, for bars, slices and points.
.legend__swatch--band- A softened square, for a shaded range: a confidence interval, an envelope.
Toggles
When the legend switches series on and off, each item is a <button> with aria-pressed. The legend drops the button's chrome, so the item still reads as a label, and aria-pressed="false" dims it as the off state. The page's script toggles the attribute and hides the series; keyboard focus keeps the library's focus ring.
<div class="legend">
<button class="legend__item" type="button" aria-pressed="true">
<span class="legend__swatch legend__swatch--line" style="--swatch-color: #1677ff"></span>
Europe
</button>
</div>