Legend

Names each series in a chart, so its colours can be read.

Live React portVue source: WildLegend.vueStorybook story: Data Display/LegendReact component: Legend

Try it

Change the number of series and add a reference to see which colour each key takes.

Block 3Block 7Block 12Last 7 days
Series
Reference
Period
<Legend
  items={[
    { label: 'Block 3' },
    { label: 'Block 7' },
    { label: 'Block 12' },
  ]}
  period="Last 7 days"
/>

When to use

  • Use a legend above a chart with two or more series. A lone series needs none, because the card title names it.
  • With four series or fewer, also turn on the chart’s end labels, so each line is named where it ends.
  • Add a period on the right when the chart covers a time range.
  • Use a hollow key (dashed) for a reference series, such as a farm average, to match its hollow dots.
Don’t use it
  • To switch what the chart shows. Keys aren’t buttons, so use a Segmented controller.
  • For more than five series. The ramp has five colours, so split the chart or use a Table.

Anatomy

A key and a label for each series, then an optional period on the right. On a narrow card the keys wrap to a second line.

Block 3Block 7Block 12Last 7 days
keys, labels and period
Block 3Block 7Block 12Block 15Last 7 days
wrapped on a narrow card
<Legend
  items={[
    { label: 'Block 3' },
    { label: 'Block 7' },
    { label: 'Block 12' },
  ]}
  period="Last 7 days"
/>

Colours

Leave out color and solid keys take the series ramp in order, as the line chart’s lines do. A reference key is hollow and grey, so it stands out by its shape as well as its colour.

Block 3Block 7Block 12Block 15Block 21
five series
Block 3Farm average
with a reference
<Legend
  items={[
    { label: 'Block 3' },
    { label: 'Block 7' },
    { label: 'Block 12' },
    { label: 'Block 15' },
    { label: 'Block 21' },
  ]}
/>

<Legend
  items={[
    { label: 'Block 3' },
    { label: 'Farm average', dashed: true },
  ]}
/>
Pass color when the chart sets its own, so each key matches its line.

Content

  • Name series that measure the same thing by what differs between them: Block 3, 10 cm, Farm average.
  • Keep the period short: Today, Last 7 days, 7-day forecast.
  • Use sentence case, and keep each label to a few words so the keys fit on one line.

Accessibility

A screen reader reads each label in order, then the period, and the keys are silent. Give the chart an ariaLabel that names the same series.

KeyWhat it does
TabPasses over the legend, which has nothing to operate.

Props

PropTypeDefaultDescription
items{ label, color?, dashed? }[]—One key per series, in the chart’s order.
items[].labelstring—The series name. See Content for when to add a unit.
items[].colorstringramp or greyKey colour. Leave out to match the line chart.
items[].dashedbooleanfalseA hollow grey key, for a reference series.
periodstring—The time range, on the right.

Tokens

TokenValueWhere it lands
SERIES_RAMP#1877F2Solid keys, in order; blue-1000 first.
SERIES_REFERENCE#7F7D83A reference key, grey-900. 4.1:1.
T.legend#2D2B32Labels, grey-1100.
T.ink4#4F4D55The period, grey-1000.
--font-size-xs11pxLabels and the period.
--font-weight-bold600Labels.
--font-weight-semibold500The period.
(no token)9px, 3px cornersThe key.
(no token)2pxThe dashed key’s outline.
--spacing-1-56pxKey to label.
--spacing-3-514pxBetween keys.
--spacing-28pxBetween wrapped lines.
--spacing-312pxBelow the legend, above the plot.