LabelList
Related Links
Parent Components
LabelList consumes context provided by these components:
anglenumberoptional
Text rotation angle in degrees. Positive values rotate clockwise, negative values rotate counterclockwise.
DEFAULT:
0backgroundTextBackgroundProps | false | trueoptional
Draws a rectangle behind each label, for example to keep labels readable on top of filled shapes.
truedraws the background with the styles from the theme'sgraphicalItems[n].label.background. If neither sets afill, the fill is thepageBackgroundcolor from the theme, or white when no theme is set.- An object accepts SVG
<rect>attributes such asfill,strokeandrx, and apadding. It is merged over the theme styles key by key. falsedraws no background, even if the theme turns backgrounds on.undefineduses the theme'sgraphicalItems[n].label.background, and draws no background without a theme.
Each background is sized from its rendered label and follows curved label paths. It is not drawn for custom
content.In a chart, the rectangles render in a zIndex layer below the labels, so overlapping labels never cover each other's text.
Available since Recharts 3.11
FORMAT:
<LabelList position="inside" background /> <LabelList position="inside" background={{ fill: '#fff', rx: 2, padding: 4 }} />clockWisebooleanoptional
The parameter to calculate the view box of label in radial charts.
contentFunction | ReactNodeoptional
If set a React element, the option is the customized React element of rendering each label. Use an SVG element or component, such as
<text>or<g>. HTML elements such as<div>are not valid inside the chart SVG and may trigger React DOM warnings. If set to a function, the function is called once for each itemFORMAT:
<LabelList content={CustomizedLabel} />dataKeyFunction | number | stringoptional
Decides how to extract the value of each label from the data:
string: the name of the field in the data object;number: the index of the field in the data;function: a function that receives the data object and returns the value of each label.
If set, then valueAccessor will be ignored.
Scatter requires this prop to be set. Other graphical components will show the same value as the dataKey of the component by default.
fillstringoptional
The text color of every label. It wins over the theme.
Without it, and without a theme, each label takes the fill of its data entry, if there is one.
With a theme, a
fillin the theme'sgraphicalItems[n].label.styleapplies first. Otherwise each label picks a color automatically:- A label on top of a filled shape (Bar, Funnel, Pie, RadialBar) takes the
pageBackgroundcolor, or thetypographycolor if there is no page background. A shape withfill="none"ortransparentis not filled, so its labels count as next to it. - A label next to its shape, and every label of Line, Area, Radar and Scatter, takes the color of its shape.
- A label with a
backgroundorhalotakes the color of its shape too. - A label at an
{ x, y }position takes thetypographycolor.
Custom
contentreceives the resolved color as itsfillprop.FORMAT:
<LabelList position="inside" fill="#000" />Examples:
- A label on top of a filled shape (Bar, Funnel, Pie, RadialBar) takes the
formatterFunctionoptional
Function to customize how content is serialized before rendering.
This should return a renderable text - something that the Text component can render. Typically, a string or number. Custom components are not supported here - use the
contentprop instead.haloTextHaloProps | false | trueoptional
Draws an outline around the letters of each label, as a lighter alternative to
background.truedraws the halo with default styles. The stroke is thepageBackgroundcolor from the theme, or white when no theme is set.- An object accepts
stroke,strokeWidth,strokeOpacityandstrokeLinejointo set them explicitly. falseorundefineddraws no halo.
Unlike
background, a halo needs no measurement, works during server-side rendering, and works for labels that follow a curved path (insideStart,insideEndandendin polar charts).Available since Recharts 3.11
FORMAT:
<LabelList position="inside" halo /> <LabelList position="inside" halo={{ stroke: '#fff', strokeWidth: 4 }} />idstringoptional
Unique identifier of this component. Used as an HTML attribute
id.offsetnumber | stringoptional
The offset to the specified "position". Direction of the offset depends on the position.
DEFAULT:
5Examples:
position"bottom" | "center" | "centerBottom" | "centerTop" | "end" | "inside" | "insideBottom" | "insideBottomLeft" | "insideBottomRight" | "insideEnd" | "insideLeft" | "insideRight" | "insideStart" | "insideTop" | "insideTopLeft" | "insideTopRight" | "left" | "middle" | "outside" | "right" | "top" | { x?: string | number | undefined; y?: string | number | undefined; }optional
The position of label relative to the view box.
DEFAULT:
"middle"textBreakAllbooleanoptional
DEFAULT:
falsevalueAccessorFunctionoptional
The accessor function to get the value of each label. Is ignored if dataKey is specified.
Examples:
zIndexnumberoptional
Z-Index of this component and its children. The higher the value, the more on top it will be rendered. Components with higher zIndex will appear in front of components with lower zIndex. If undefined or 0, the content is rendered in the default layer without portals.
Available since Recharts 3.4
DEFAULT:
2000Examples: