shadcn.io is not affiliated with official shadcn/ui
Chart examples · Tooltip
Tooltip - Formatter Chart for React
A chart tooltip that formats each row with its value and a unit.
Use a formatter to add a unit or change how each value reads while keeping the rows simple. Each row shows the series' label and its value followed by kcal.
Preview
Installation
FAQ
What does the formatter render?
ChartTooltipContent sets formatter to formatItem. That function receives the value and the series name. It prints the label from config (Running or Swimming), then the value and the text kcal. The value uses font-mono and tabular-nums.
Does the default dot still show?
No. A formatter replaces the whole row, so this tooltip has no color dot and no built-in value. The row is the markup formatItem returns, with min-w-[130px]. The name falls back to the series key when config has no entry for it.
Why is the date missing from the tooltip?
hideLabel hides the tooltip title. The date stays on XAxis, where tickFormatter is formatWeekday, a short weekday of the date string. axisLine and tickLine are false, and tickMargin is 10.
Why is a tooltip already open?
ChartTooltip sets defaultIndex={1} and cursor={false}. Index 1 is 2024-07-16. cursor={false} turns the hover cursor off. BarChart sets accessibilityLayer.
Related
- Tooltip - Default ChartThe default chart tooltip, with a label
- Tooltip - Advanced ChartA chart tooltip with a custom row for
- Tooltip - Label Formatter ChartA chart tooltip that formats its date
- A bar chart with a labelA bar chart with each bar's value printed
- Tooltip - Icons ChartA chart tooltip showing each series' icon
- A line chart with a labelA line chart with a dot on each point and