Displays a legend for the chart. The Legend component renders an HTML element (not SVG) showing labels and colors for each data series.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/recharts/recharts/llms.txt
Use this file to discover all available pages before exploring further.
Usage
Props
Content
Renders the content of the legend.This should return HTML elements, not SVG elements.Options:
- Not set: Uses DefaultLegendContent component
ReactElement: Element is cloned with extra propsfunction: Called to render HTML elements
Dimensions
Width of the legend.Accepts CSS style string values like “100%” or “fit-content”, or number values like 400.
Height of the legend.Accepts CSS style string values like “100%” or “fit-content”, or number values like 400.
Layout
The layout of legend items.
horizontal: Items arranged in rowsvertical: Items arranged in columns
The horizontal alignment of the legend container.
The vertical alignment of the legend container.
bottom: Shows below chart, chart height reduces automaticallytop: Shows above chart, chart height reduces automaticallymiddle: Shows in middle, covering content, chart height unchanged
Icon
The size of the legend icon, in pixels.
iconType
'line' | 'plainline' | 'square' | 'rect' | 'circle' | 'cross' | 'diamond' | 'star' | 'triangle' | 'wye'
The type of icon.If not specified, uses the legendType from each graphical item.
Styling
CSS styles applied to the wrapper
div element.The color used for inactive legend items.
Items
The array of legend items.Typically this is automatically populated from chart data. You can override it to customize legend items.
Function to determine uniqueness of legend items.Used to filter duplicate items.
Sorts legend items.Options:
'value': Sort alphabetically by label'dataKey': Sort by dataKeyfunction: Custom sort functionnull: No sorting (order may vary between renders)
Portal
If defined, Legend uses this element as a target for rendering using React Portal.If undefined, Legend renders inside the recharts-wrapper element.
Interaction
Event handler for click events on legend items.Signature:
(item: LegendPayload, index: number, e: React.MouseEvent) => voidEvent handler for mouse enter events on legend items.
Event handler for mouse leave events on legend items.
Other
The width of the chart.Automatically provided by chart context.
The height of the chart.Automatically provided by chart context.
The margin of the chart.Automatically provided by chart context.