Legend
Polymorphic legend component that adapts to cartesian and geo contexts.
The <Legend> component auto-discovers its context and renders the appropriate legend style.
Behaviour
- Inside
<Chart>with cartesian marks — renders series toggles (click to show/hide). Auto-discovers registered marks (<LineMark>,<BarMark>, etc.) from Chart context. - Inside
<Chart>with<Choropleth>— renders a quantile colour bar with min/max labels and a spring-animated marker tracking the hovered value. - Explicit props — pass
breakpoints+colorsfor manual quantile mode, oritemsfor manual series mode.
Cartesian usage
When placed inside a <Chart> with marks, Legend auto-discovers them — no props needed:
import { Chart, LineMark, BarMark, Legend } from "@exhibit/charts";
<Chart data={data} xDataKey="month" height={360}>
<BarMark dataKey="sales" name="Sales" color="#3b82f6" />
<LineMark dataKey="target" name="Target" color="#f59e0b" />
<Legend />
</Chart>Click a legend item to toggle its series visibility.
Geo usage
When placed inside a <Chart> with <Choropleth>, Legend auto-discovers the quantile scale:
import { Chart, Choropleth, Legend } from "@exhibit/charts";
<Chart height={620}>
<Choropleth geoData={geo} data={popData} featureIdKey="LAD24CD" featureNameKey="LAD24NM" />
<Legend formatValue={(v) => v.toLocaleString()} />
</Chart>Props
| Prop | Type | Default | Description |
|---|---|---|---|
items | LegendItem[] | — | Manual series items (overrides auto-discovery) |
breakpoints | number[] | — | Manual quantile breakpoints |
colors | string[] | — | Manual quantile colour stops |
formatValue | (v: number) => string | toLocaleString | Format breakpoint labels |
hoveredValueRef | RefObject<number | null> | — | Ref-based hover value for the marker |
position | "top" | "bottom" | "bottom" | Render position relative to chart |
className | string | — | Additional CSS class |
LegendItem
| Field | Type | Default | Description |
|---|---|---|---|
key | string | required | Unique identifier |
label | string | required | Display text |
color | string | required | Indicator colour |
type | "line" | "square" | "square" | Indicator shape |