Tooltip
The Tooltip component displays a floating box with data values when hovering over or clicking on chart elements. It can be configured to show information for individual data points or for all points at a specific axis coordinate. The appearance and content of the tooltip can be customized via props.
相关链接
父组件
Tooltip consumes context provided by these components:
Props
activebooleanoptional
If true, then Tooltip is always displayed, once an activeIndex is set by mouse over, or programmatically. If false, then Tooltip is never displayed. If undefined, Recharts will control when the Tooltip displays. This includes mouse and keyboard controls.
allowEscapeViewBoxAllowInDimensionoptional
This option allows the tooltip to extend beyond the viewBox of the chart itself.
默认值:
{"x":false,"y":false}animationDurationnumberoptional
Specifies the duration of animation, the unit of this option is ms.
默认值:
400animationEasing"ease" | "ease-in" | "ease-in-out" | "ease-out" | "linear"optional
The type of easing function.
默认值:
"ease"axisIdnumber | stringoptional
Tooltip always attaches itself to the "Tooltip" axis. Which axis is it? Depends on the layout:
- horizontal layout -> X axis
- vertical layout -> Y axis
- radial layout -> radial axis
- centric layout -> angle axis
Tooltip will use the default axis for the layout, unless you specify an axisId.
默认值:
0contentFunction | ReactNodeoptional
Renders the content of the tooltip.
This should return HTML elements, not SVG elements.
- If not set, the DefaultTooltipContent component is used.
- If set to a React element, this element will be cloned and extra props will be passed in.
- If set to a function, the function will be called and should return HTML elements.
contentStyleReact.CSSPropertiesoptional
The style of tooltip content which is a dom element.
默认值:
{}cursorReact.SVGProps<SVGElement> | ReactNode | false | trueoptional
If set false, no cursor will be drawn when tooltip is active. If set a object, the option is the configuration of cursor. If set a React element, the option is the custom react element of drawing cursor.
默认值:
truedefaultIndexnull | number | stringoptional
filterNullbooleanoptional
When an item of the payload has value null or undefined, this item won't be displayed.
默认值:
trueformatterFormatter<TValue, TName>optional
Function to customize the value in the tooltip. If you return an array, the first entry will be the formatted "value", and the second entry will be the formatted "name"
includeHiddenbooleanoptional
If true, the tooltip will display information about hidden series. Defaults to false. Interacting with the hide property of Area, Bar, Line, Scatter.
默认值:
falseisAnimationActive"auto" | false | trueoptional
If set false, animation of tooltip will be disabled. If set "auto", the animation will be disabled in SSR and enabled in browser.
默认值:
"auto"itemSorter"dataKey" | "name" | "value" | Functionoptional
Sorts tooltip items. Defaults to 'name' which means it sorts alphabetically by graphical item
nameproperty.默认值:
"name"itemStyleReact.CSSPropertiesoptional
The style of default tooltip content item which is a li element.
默认值:
{}labelClassNamestringoptional
labelFormatterFunctionoptional
The formatter function of label in tooltip.
labelStyleReact.CSSPropertiesoptional
The style of default tooltip label which is a p element.
默认值:
{}offsetCoordinate | numberoptional
The offset size between the position of tooltip and the mouse cursor position. When a number is provided, the same offset is applied to both x and y axes.
When a Coordinate object is provided, you can specify different offsets for each axis (x and y as numbers)
默认值:
10payloadUniqByUniqueFunc<TooltipPayloadEntry> | false | trueoptional
portalHTMLElement | nulloptional
If portal is defined, then Tooltip will use this element as a target for rendering using React Portal: https://react.dev/reference/react-dom/createPortal
If this is undefined then Tooltip renders inside the recharts-wrapper element.
positionPartial<Coordinate>optional
If this field is set, the tooltip will be displayed at the specified position regardless of the mouse position.
You can set a single field (x or y) and let the other field be calculated automatically based on the mouse position.
reverseDirectionAllowInDimensionoptional
默认值:
{"x":false,"y":false}separatorstringoptional
The separator between name and value.
默认值:
" : "trigger"click" | "hover"optional
If
hoverthen the Tooltip shows on mouse enter and hides on mouse leave.If
clickthen the Tooltip shows after clicking and stays active.默认值:
"hover"useTranslate3dbooleanoptional
默认值:
falsewrapperClassNamestringoptional
wrapperStyleReact.CSSPropertiesoptional
CSS styles to be applied to the wrapper
divelement.默认值:
{}示例: