Docs/General Components/Legend

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>;
LineChart
line-basic.tsxOpen ↗
Loading source...

Props

PropTypeDefaultDescription
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
iconTypestring"line"Shape of the color indicator: "line", "square", "diamond", etc.
iconSizenumber14Size 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
wrapperStyleJSX.CSSProperties{}Styles for the legend wrapper
widthnumber | string—Explicit legend width (vertical layout only)
heightnumber | string—Explicit legend height (vertical layout only)

Notes

  • Legend entries are auto-populated from series components (Line, Bar, Area, etc.) that have a name prop or dataKey.
  • The legend is positioned inside the chart's bounds by default; use wrapperStyle to override positioning.
  • verticalAlign stacks entries vertically when layout="vertical".
  • content is called with { payload, chartWidth, chartHeight, margin, ... } for full custom rendering.
  • iconType values: "line", "square", "cross", "diamond", "star", "triangle", "wye".

See also

  • LineChart — common chart with legend
  • Tooltip — often paired with legend for series selection
  • Bar — legend updates with multi-series bar charts