shadcn.io is not affiliated with official shadcn/ui
Chart examples · Tooltip
Tooltip - Custom Label Chart for React
A chart tooltip whose label comes from a chart config entry instead of the data.
Use labelKey when the tooltip's title should come from the chart config instead of the hovered data. Here the title reads Activities over the running and swimming rows, with line indicators.
Preview
Installation
FAQ
How does the tooltip title become Activities?
ChartTooltipContent sets labelKey="activities". That key is looked up in config, where activities has label: "Activities" and no color. The same title is used for every bar. The date stays on the axis.
What does indicator line draw?
indicator="line" draws a narrow bar in the series color beside Running and Swimming. The default indicator is dot. The same prop also accepts dashed. The row names come from those entries' label in config.
What does the axis show if the tooltip doesn't?
XAxis uses dataKey="date" and tickFormatter={formatWeekday}, which prints a short weekday from the date string. axisLine and tickLine are false, and tickMargin is 10.
Why is a tooltip open before I hover?
ChartTooltip sets defaultIndex={1} and cursor={false}. Index 1 is the second row, 2024-07-16, so that bar's tooltip renders on first paint. cursor={false} turns the hover cursor off.
Related
- Tooltip - Default ChartThe default chart tooltip, with a label
- Tooltip - Label Formatter ChartA chart tooltip that formats its date
- Tooltip - No Label ChartA chart tooltip without a label or
- Tooltip - Advanced ChartA chart tooltip with a custom row for
- A bar chartA bar chart with rounded corners
- Tooltip - Formatter ChartA chart tooltip that formats each row