Legend
Legend renders an interactive legend below (or beside) the chart, displaying the name and color of each series. Clicking a legend entry can trigger custom handlers or hide/show the series.
import { LineChart, Line, XAxis, YAxis, Legend } from "solid-recharts";
<LineChart data={data}>
<XAxis dataKey="name" />
<YAxis />
<Legend layout="horizontal" align="center" />
<Line dataKey="uv" stroke="#8884d8" name="UV" />
<Line dataKey="pv" stroke="#82ca9d" name="PV" />
</LineChart>;
Loading source...
Props
| Prop | Type | Default | Description |
|---|---|---|---|
layout | "horizontal" | "vertical" | "horizontal" | Legend flow direction |
align | "left" | "center" | "right" | "center" | Horizontal alignment (vertical layout) or left/center/right for horizontal |
verticalAlign | "top" | "middle" | "bottom" | "bottom" | Vertical alignment |
iconType | string | "line" | Shape of the color indicator: "line", "square", "diamond", etc. |
iconSize | number | 14 | Size of the color indicator in pixels |
formatter | (value, entry) => string | — | Format the series name displayed in the legend |
content | (props) => JSX.Element | — | Custom legend rendering function |
onClick | (entry) => void | — | Called when a legend entry is clicked |
onMouseEnter | (entry) => void | — | Called when the mouse enters a legend entry |
onMouseLeave | (entry) => void | — | Called when the mouse leaves a legend entry |
wrapperStyle | JSX.CSSProperties | {} | Styles for the legend wrapper |
width | number | string | — | Explicit legend width (vertical layout only) |
height | number | string | — | Explicit legend height (vertical layout only) |
Notes
- Legend entries are auto-populated from series components (
Line,Bar,Area, etc.) that have anameprop ordataKey. - The legend is positioned inside the chart's bounds by default; use
wrapperStyleto override positioning. verticalAlignstacks entries vertically whenlayout="vertical".contentis called with{ payload, chartWidth, chartHeight, margin, ... }for full custom rendering.iconTypevalues:"line","square","cross","diamond","star","triangle","wye".