Skip to main content
Tooltips and legends make your charts interactive and easier to understand. This guide covers configuration and customization.

Tooltip basics

The Tooltip component displays data values when users hover over or click chart elements.

Default tooltip

Add a tooltip with default styling:

Tooltip trigger modes

Control when tooltips appear using the trigger prop:
Source: https://github.com/recharts/recharts/blob/main/src/component/Tooltip.tsx:230-235

Shared vs individual tooltips

The shared prop controls whether the tooltip shows data for all series or just one:
Source: https://github.com/recharts/recharts/blob/main/src/component/Tooltip.tsx:216-227

Tooltip customization

Styling the tooltip

Customize appearance using style props:
Available style props:
  • contentStyle: Styles the tooltip container
  • itemStyle: Styles each data item (<li> element)
  • labelStyle: Styles the label (<p> element)
  • wrapperStyle: Styles the outer wrapper div
Source: https://github.com/recharts/recharts/blob/main/src/component/Tooltip.tsx:120-243

Custom separator

Change the separator between name and value:
Default is " : ".

Formatting values

Use the formatter prop to customize how values display:
Formatter receives:
  • value: The data value
  • name: The series name
  • item: The complete tooltip payload entry
  • index: The item index
  • payload: All tooltip data
Source: https://github.com/recharts/recharts/blob/main/src/component/Tooltip.tsx:139-148

Formatting labels

Customize the tooltip label (typically the x-axis value):
Source: https://github.com/recharts/recharts/blob/main/src/component/Tooltip.tsx:174-177

Custom tooltip content

Create a completely custom tooltip:
Custom content receives:
  • active: Whether tooltip is active
  • payload: Array of data for all visible series
  • label: The axis label
  • coordinate: Mouse position
  • accessibilityLayer: Accessibility settings
Source: https://github.com/recharts/recharts/blob/main/src/component/Tooltip.tsx:108-119

Tooltip positioning

Offset

Control distance from cursor:
Default is 10. Source: https://github.com/recharts/recharts/blob/main/src/component/Tooltip.tsx:184-190

Fixed position

Lock tooltip to a specific position:
You can also set just one coordinate:
Source: https://github.com/recharts/recharts/blob/main/src/component/Tooltip.tsx:200-206

Allow escape viewbox

Let tooltip extend beyond chart boundaries:
Default is { x: false, y: false }. Source: https://github.com/recharts/recharts/blob/main/src/component/Tooltip.tsx:80-85

Advanced tooltip features

Filter null values

Hide entries with null values:
Source: https://github.com/recharts/recharts/blob/main/src/component/Tooltip.tsx:134-137

Include hidden series

Show data from hidden series:
Source: https://github.com/recharts/recharts/blob/main/src/component/Tooltip.tsx:150-156

Portal rendering

Render tooltip outside the chart container to avoid clipping:
Source: https://github.com/recharts/recharts/blob/main/src/component/Tooltip.tsx:192-198

Cursor customization

Customize or disable the cursor shown on hover:
Source: https://github.com/recharts/recharts/blob/main/src/component/Tooltip.tsx:126-131

Legend basics

The Legend component shows labels for each data series.

Default legend

Legend alignment

Control vertical and horizontal positioning:
Options:
  • verticalAlign: "top", "middle", "bottom"
  • align: "left", "center", "right"
Source: https://github.com/recharts/recharts/blob/main/src/component/Legend.tsx:147-156

Legend layout

Control how legend items are arranged:
Source: https://github.com/recharts/recharts/blob/main/src/component/DefaultLegendContent.tsx

Legend customization

Styling

Customize legend appearance:
Source: https://github.com/recharts/recharts/blob/main/src/component/Legend.tsx:111-114

Custom content

Create a custom legend:
Source: https://github.com/recharts/recharts/blob/main/src/component/Legend.tsx:98-110

Sorting legend items

Control the order of legend items:
Source: https://github.com/recharts/recharts/blob/main/src/component/Legend.tsx:136-145

Best practices

Name your data seriesAlways provide a name prop for better tooltips and legends:
Tooltip animationsBy default, tooltips respect the user’s prefers-reduced-motion setting. Set isAnimationActive={false} to disable animations completely.
Portal rendering limitationsWhen using a custom portal, tooltip positioning is calculated relative to the portal element, not the chart.