shadcn.io is an independent project built on shadcn/ui
On this page17 sections
Installation
The command adds the example above to components/charts/ and, the first time, the chart kit to components/ui/charts/. Both are source files in your project from then on: read them, change them, delete what you don't use.
Usage
Add <ChartTooltip /> inside a line, area, bar, composed, candlestick, scatter or live line chart. With no props it shows a row per series, named by each series' label.
import {
ChartTooltip,
Grid,
Line,
LineChart,
XAxis,
} from "@/components/ui/charts";
const data = [
{ app: 640, date: new Date(2026, 9, 1), web: 1180 },
{ app: 702, date: new Date(2026, 9, 2), web: 1320 },
{ app: 688, date: new Date(2026, 9, 3), web: 1260 },
{ app: 754, date: new Date(2026, 9, 4), web: 1510 },
{ app: 731, date: new Date(2026, 9, 5), web: 1470 },
];
export const SessionsChart = () => (
<LineChart ariaLabel="Sessions by platform" data={data}>
<Grid horizontal />
<Line dataKey="web" label="Web" />
<Line dataKey="app" label="App" stroke="var(--chart-2)" />
<XAxis />
<ChartTooltip />
</LineChart>
);Anatomy
ChartTooltip is the only part you need. TooltipIndicator and TooltipDot are siblings that restyle it, and the rest are for building a panel of your own in content.
<LineChart data={data}>
<Line dataKey="users" label="Users" />
<XAxis />
<ChartTooltip showDatePill={false} />
<TooltipIndicator colorEdge="var(--chart-1)" width="thin" />
<TooltipDot size={6} strokeWidth={3} />
</LineChart>ChartTooltip: The crosshair, the dots, the date pill and the panel, each with its own props.TooltipIndicator: The crosshair's width, color and dash, set as a child of the chart.TooltipDot: The hover dots' size, stroke and color, set the same way.TooltipContent: The default panel body: a title and a list of rows.TooltipBox: A plain wrapper for a body you write, at least 140 px wide.TooltipHeader: A header row with a rule under it, for the top of a custom body.TooltipDetail: Content that unfolds only while apinnabletooltip is pinned.ChartCrosshair: A second crosshair with a horizontal line and a value pill on the y axis.
Crosshair and dots
showCrosshair, showDots and showDatePill turn each piece off. The crosshair takes indicatorColor, indicatorDasharray and indicatorWidth, from "line" (1 px) to "thick" (8 px), and the dots take dotSize (5) and dotStrokeWidth (2).
On a bar chart, dotVariant="ring" draws a rounded square around the top of each hovered bar instead of a dot.
Custom rows
rows replaces the panel's rows and keeps everything else. It gets the hovered row and returns { color, label, value } items, so you can rename a series, format a value or add one that no series draws, like a ratio.
A number value is formatted with thousands separators. Pass a string to format it yourself.
Your own panel
content replaces the whole body. It gets { point, index }, the hovered row and its position in data, and returns your markup. Wrap it in TooltipBox, or return TooltipContent with your own title and rows to keep the default look.
Pinned tooltips
With pinnable, a click, Enter or Space pins the tooltip where it is. The panel then takes the pointer, so it can hold links and buttons, and TooltipDetail inside content unfolds with more. Another click or Escape lets it go.
content also gets pinned and dismiss for a close button. Pinning works on line and area charts.
Synced tooltips
Line, area and bar charts with the same syncId share one cursor. Hover a day on one and the others show their crosshair, dots and date pill at that day, while the panel stays on the chart under the pointer.
Price crosshair
<ChartCrosshair /> adds a horizontal line at the pointer and a pill on the y axis with the value under it. numberFlow rolls the pill's digits, and snap={false} lets the vertical line follow the pointer instead of the hovered row. Pair it with showCrosshair={false} on the tooltip so there's one vertical line.
Customization
The kit is in your project, in components/ui/charts/: your framework's components over a shared core/. Change a default there and every chart picks it up.
className goes on the chart's container, so size and spacing are utility classes.
className on ChartTooltip goes on the panel. For a change every chart should get, such as the padding or the date format, edit TooltipContent in your copy of the kit: it's the default body everywhere.
To add a note or a link under the default rows without replacing them, pass it as the tooltip's children.
<ChartTooltip
content={({ point }) => (
<TooltipBox>
<TooltipHeader>{String(point.day)}</TooltipHeader>
<div className="px-3 py-2 font-medium text-sm tabular-nums">
{Number(point.revenue).toLocaleString()} USD
</div>
</TooltipBox>
)}
/>Where a part renders content of its own, you pass it in. In React:
ChartTooltip:content={({ point, index }) => …}
Animation
The crosshair and the dots spring to each row. The panel follows on its own spring, set by damping on a 0 to 100 scale (20 by default). Lower values bounce more, higher ones trail further behind, and 0 turns the spring off.
matchCrosshair puts the panel on the crosshair's spring instead. boxSpringConfig takes your own stiffness and damping and wins over both.
Theming
Every color in the kit is one of your theme's tokens or a mix of them, except --chart-positive, a fixed green. A preset or the .dark class restyles the chart, and overriding a token in your CSS changes it everywhere.
The panel reads your --popover colors and --radius-lg corners through the --chart-tooltip-* tokens. Override those to change every chart's tooltip, or use className for one.
| Token | Default | Paints |
|---|---|---|
--chart-tooltip-background | --popover | the tooltip panel |
--chart-tooltip-foreground | --popover-foreground | the tooltip's values |
--chart-tooltip-muted | --muted-foreground | the tooltip's labels |
--chart-crosshair | --muted-foreground at 75% | the hover line |
--chart-date-pill-background | --primary | the date pill on hover |
--chart-date-pill-foreground | --primary-foreground | the date pill's text |
--chart-background | --card | dot halos, the gaps between stacked marks |
:root {
--chart-tooltip-background: var(--card);
--chart-crosshair: var(--primary);
}Accessibility
The panel is a polite live region, so as the arrow keys move the focus, a screen reader reads the hovered row. A pinned tooltip becomes a non-modal dialog.
A content panel is read as written. Keep the value in text rather than only in a bar or a color.
- Tab
- Moves focus to the chart.
- Arrow Right
- Moves the tooltip to the next row.
- Arrow Left
- Moves the tooltip to the previous row.
- Enter
- Pins the tooltip on a chart with
pinnable. Space does the same. - EscEscape
- Releases a pinned tooltip.
FAQ
Which charts can use the chart tooltip, and what does it show by default?
Add <ChartTooltip /> inside a line, area, bar, composed, candlestick, scatter, stream or live line chart. On a time-series chart it draws a crosshair, a dot on each series, a date pill on the x axis and a panel with one row per series, named by each series' label.
Sparklines have no tooltip. They report the hovered point through onHoverChange and you render the value yourself.
How do I format the values in a chart tooltip?
Pass rows to <ChartTooltip>. It receives the hovered row and returns a list of { color, label, value } items, which replace the default rows and keep the rest of the panel.
A number value is printed with thousands separators, and a string is shown as you wrote it, so return a string for currency, percentages or units. rows can also add a line that no series draws, such as a ratio of two fields.
How do I render my own content in a chart tooltip?
Pass content to <ChartTooltip>. It receives { point, index }, the hovered row and its position in data, and returns the body of the panel.
Wrap your markup in <TooltipBox> for the panel's frame, with <TooltipHeader> for a title row over a rule. To keep the default look with your own text, return <TooltipContent> with a title and rows. To add a note under the default rows without replacing them, pass it as the tooltip's children.
How do I hide the crosshair, the dots or the date pill of a chart tooltip?
Each piece has its own switch on <ChartTooltip>: showCrosshair={false}, showDots={false} and showDatePill={false}. The panel stays, so a chart can keep its values on hover without the extra marks.
To restyle them instead, indicatorColor, indicatorDasharray and indicatorWidth change the crosshair, and dotSize and dotStrokeWidth change the dots.
How do I keep a chart tooltip open on click?
Add pinnable to <ChartTooltip>. A click on the chart, or Enter or Space from the keyboard, pins the tooltip where it is. The panel then takes the pointer, so it can hold links and buttons.
Inside content, a <TooltipDetail> unfolds only while the tooltip is pinned, and content receives pinned and a dismiss function for a close button. Another click or Escape lets it go. Pinning works on line and area charts.
How do I change the date shown in a chart tooltip?
The panel's heading is the hovered date with its weekday, such as Mon, Jan 5. To write it another way, return <TooltipContent> from content with your own title and rows.
For the pill on the x axis, pass one string per row as dateLabels, paired with labels on <XAxis>. Both then show your text, such as sprints or quarters, instead of dates.
How do I read the hovered row outside the chart tooltip?
On a line, area or bar chart, pass onActiveIndexChange. It is called with the index into data of the row under the pointer or the keyboard focus, and with null when the focus leaves, so a table or a headline number can follow the chart.
The other direction works too: set activeIndex and the chart shows its crosshair, dots and tooltip on that row. A component rendered inside the chart can read the hovered row and its index from useChart().tooltipData.
How do I sync the chart tooltip across several charts?
Give the charts the same syncId. Line, area and bar charts with one id share a cursor: hover a day on one and the others show their crosshair, dots and date pill at that day.
The panel itself stays on the chart under the pointer. Bar charts match on the same category instead of the same date.
Which frameworks does the tooltip support?
React, Vue, Svelte and Solid. One core on TanStack Charts draws the tooltip in each, so the components and props on this page are the same everywhere, and switching framework at the top of the page changes the preview, the code and the install command.
Only the spelling follows the framework: class for className outside React, scoped slots for render props in Vue and snippets in Svelte.
How do I add the tooltip to my project?
Sign in, then copy the command under Installation: npx shadcn@latest add with the chart's URL. It adds the example at the top of this page as components/charts/chart-tooltip-standard, the chart kit to components/ui/charts the first time you install a chart, and @tanstack/charts.
Both are source files in your project from then on. Swap the sample rows for your own data and change whatever you need.
Is the tooltip free?
Yes. The tooltip and every example of it are free to use in personal and commercial projects. Seeing the code and installing it takes a free account, one tap with Google or GitHub.
The charts are bklit's (bklit-ui, MIT), rebuilt on TanStack Charts and drawn in your shadcn/ui theme's tokens.
API reference
ChartTooltip
showDatePill?boolean
Show the date pill that rides along the bottom of the plot.
- Default
true
showCrosshair?boolean
Show the vertical crosshair line. Bar charts leave it off unless this is true (the dots and the category pill mark the bar).
- Default
true
showDots?boolean
Show a dot on every series at the hovered position.
- Default
true
dotVariant?"dot" | "ring"
Dot style: a filled "dot" or a transparent "ring" square. Read by BarChart only.
- Type
"dot" | "ring"- Default
"dot"
dotSize?number
Dot radius in px.
- Default
5
dotRadiusFraction?number
Corner radius of the "ring" variant as a fraction of its side (0 is square, 0.5 is a circle). Read by BarChart only.
- Default
0.25
dotScale?number
Multiplier applied to the dot or ring size. Read by BarChart and LiveLineChart.
- Default
1
dotStrokeWidth?number
Stroke width of the dots in px.
- Default
2
indicatorColor?string | ((point: Record<string, unknown>) => string)
Color of the crosshair. Only a string is applied; the function form that bklit-ui accepts is ignored and the default is used.
- Type
string | ((point: Record<string, unknown>) => string)- Default
"var(--chart-crosshair)"
content?(props: { point: Record<string, unknown>; index: number; pinned?: boolean; dismiss?: () => void }) => ReactNode
Replaces the default tooltip panel body. Receives the hovered data row and its index; with pinnable, also whether the panel is pinned and a dismiss that unpins it (for a close button in a pinned panel's detail).
- Type
(props: { point: Record<string, unknown>; index: number; pinned?: boolean; dismiss?: () => void }) => ReactNode
pinnable?boolean
A click (or Enter, or Space) on the chart pins the tooltip where it is: the panel takes the pointer, so its content can grow into detail and hold controls, until another click, Escape or dismiss lets it go.
- Default
false
rows?(point: Record<string, unknown>) => { readonly color: string; readonly label: string; readonly value: string | number }[]
Replaces the default rows (one per series) with your own list of { color, label, value }.
- Type
(point: Record<string, unknown>) => { readonly color: string; readonly label: string; readonly value: string | number }[]
dotColor?string | ((point: Record<string, unknown>, line: ChartLineConfig) => string)
Fill of the tooltip dots. A function receives the hovered row and the series config, and is called again each time the hovered row changes. Defaults to each series' color; a ProfitLossLine's dot takes the color of the hovered value's sign.
- Type
string | ((point: Record<string, unknown>, line: ChartLineConfig) => string)
children?ReactNode
Extra content rendered below the rows in the default panel, for example marker details. Without it, a chart with ChartMarkers lists the markers on the hovered date there.
className?string
Extra class name for the tooltip panel.
springConfig?SpringConfig
Spring for the floating panel when matchCrosshair is on. Defaults to the chart's tooltip spring.
matchCrosshair?boolean
Make the floating panel follow the pointer with the same spring as the crosshair instead of damping.
- Default
false
damping?number
Spring damping for the floating panel when matchCrosshair is off, on bklit's 0 to 100 scale: lower is bouncier, higher slower, 0 moves the panel instantly. The default, 20, is the snappy hover spring (stiffness 3600, damping 120); every other value is bklit's spring for it played six times faster.
- Default
20
indicatorDasharray?string
Dash pattern of the crosshair. Omit for a solid line.
indicatorFadeEdges?IndicatorFadeEdges
Vertical fade of the crosshair: both ends, the top, the bottom, or none (solid).
- Default
"both"
indicatorFadeLength?number
Size of the crosshair's fade, as a percentage of its height (2 to 40).
- Default
10
indicatorEndColor?string
Bottom colour of the crosshair: it ramps from indicatorColor at the top to this at the bottom (composes with the fade).
indicatorEnd?"plot" | "point"
How far down the crosshair reaches: the whole plot, or down to the hovered point of the first series.
- Type
"plot" | "point"- Default
"plot"
dotHaloBlur?number
Blur in px on the dots' halo, for a soft glow.
- Default
0
topOffset?number
Extra gap in px between the top of the plot and the tooltip panel.
- Default
0
dateLabels?readonly string[]
The date pill's text for each data row, in row order (pair it with XAxis labels).
boxSpringConfig?SpringConfig
Spring for the floating panel. Takes priority over matchCrosshair and damping.
indicatorWidth?IndicatorWidth
Thickness of the crosshair: a width in px, or "line" (1px), "thin" (2px), "medium" (4px) or "thick" (8px).
- Default
"line"
TooltipContent
title?string
Heading above the rows, for example the formatted date.
rowsreadonly TooltipRow[]
The rows to show, one per series.
children?ReactNode
Extra content rendered below the rows, for example marker details.
className?string
Class names added to the content wrapper.
TooltipBox
visible?boolean
Render the box. Nothing is rendered when false.
- Default
true
className?string
Class names added to the box.
children?ReactNode
Content of the box.
panelStyle?CSSProperties
Inline styles merged into the box, after the defaults.
backgroundColor?string
Background color of the box (a color or a CSS variable).
TooltipHeader
children?ReactNodeclassName?stringTooltipDetail
open?boolean
Keep it unfolded whether or not the tooltip is pinned.
className?string
Extra class name for the detail's inner box (padding, a border, a gap).
children?ReactNode
The detail.
TooltipIndicator
visible?boolean
Show the crosshair. Same as showCrosshair on ChartTooltip.
- Default
true
width?IndicatorWidth
Thickness of the crosshair: a width in px, or "line" (1px), "thin" (2px), "medium" (4px) or "thick" (8px).
- Default
"line"
colorEdge?string
Color of the crosshair. Same as indicatorColor.
- Default
"var(--chart-crosshair)"
strokeDasharray?string
Dash pattern of the crosshair. Omit for a solid line. Same as indicatorDasharray.
TooltipDot
visible?boolean
Show the dots. Same as showDots on ChartTooltip.
- Default
true
color?string
Fill color of the dots. Defaults to each series' color.
size?number
Dot radius in px. Same as dotSize.
- Default
5
strokeWidth?number
Stroke width of the dots in px. Same as dotStrokeWidth.
- Default
2
variant?"dot" | "ring"
"dot" or "ring". Same as dotVariant; read by BarChart only.
- Type
"dot" | "ring"- Default
"dot"
ChartCrosshair
horizontal?boolean
Draw the horizontal line (and the value pill) at the pointer's y.
- Default
true
vertical?boolean
Draw the vertical line.
- Default
true
snap?boolean
The vertical line snaps to the hovered column; false follows the pointer, so both lines cross under it.
- Default
true
yAxisId?string | number
The axis whose scale turns the pointer's y into the pill's value. The YAxis with this id fades the ticks under the pill.
- Type
string | number- Default
"left"
side?"left" | "right"
The plot edge the pill sits on. Defaults to "right" for the right axis, else "left".
- Type
"left" | "right"
showValueLabel?boolean
Show the value pill on the axis.
- Default
true
numberFlow?boolean
Roll the pill's digits as the value changes (with format, prefix and suffix; formatValue is ignored).
- Default
false
format?ChartStatFlowFormat
Intl.NumberFormat options for the pill.
- Default
{ maximumFractionDigits: 2 }
prefix?string
Text before the value ("$").
suffix?string
Text after the value ("%").
formatValue?(value: number) => string
Formats the pill's value (without numberFlow).
- Type
(value: number) => string
stroke?string
The lines' color.
- Default
"var(--chart-crosshair)"
strokeDasharray?string
The lines' dash pattern.
- Default
"3,3"
strokeWidth?number
The lines' width.
- Default
1
springConfig?{ readonly stiffness: number; readonly damping: number }
The spring the lines and the pill follow. Defaults to the chart's tooltip spring; { stiffness: 0 }-free charts land at once.
- Type
{ readonly stiffness: number; readonly damping: number }
Examples
11 examples on React, each live with its code and its own install command.
- Chart TooltipTooltip

- Tooltip with a Dashed CrosshairTooltip

- Tooltip with a Styled IndicatorTooltip

- Tooltip with Panel MotionTooltip

- Tooltip with Custom RowsTooltip

- Tooltip with Custom ContentTooltip

Related chart types
Charts close to the tooltip: the same data drawn another way, or the type to reach for when this one stops fitting.





