shadcn.io is not affiliated with official shadcn/ui
About
Same tooltip, different mark: each series gets a narrow vertical bar in its color, as tall as its row, instead of a square dot. Use it on line and area charts, where a stroke reads more naturally than a filled square.
The label and the rows don't change. Only the indicator does, so you can compare it with the default on the same stack of running and swimming.
Installation
Usage
import { ChartTooltipIndicatorLine } from "@/components/charts/chart-tooltip-indicator-line";<ChartTooltipIndicatorLine />Customize
<ChartTooltipContent indicator="line" />is the only change from the default.- The line is a
w-1div with the item's color as its background and border. indicatoralso takesdotanddashed.- Pair
linewith line and area charts; on these bars it's here to compare with the dot.
FAQ
How do I switch the indicator?
Pass indicator="line" to ChartTooltipContent. The other values are dot, the default, and dashed.
When should I use the line instead of the dot?
A line echoes a stroke, so it matches line and area charts, where a square dot hints at a bar that isn't there. On bars, the dot is the closer match; this chart shows the line on bars only to compare.
What does the dashed indicator look like?
dashed draws a narrow outline with a dashed border in the series color. It's the usual pairing for dashed strokes, such as a forecast drawn beside actuals.
API Reference
ChartContainer
configChartConfig
Each series by its data key: its label, an icon, and a color (or a * theme color per light and dark), read by the tooltip and legend and set * as --color-<key>.
initialDimension?{ height: number; width: number; }
The size it renders at before it's measured, so the first paint isn't * empty.
- Type
{ height: number; width: number; }- Default
INITIAL_DIMENSION
className?string
Merged with the part's classes.
ChartLegend
ChartLegendContent
<div>
hideIcon?boolean
Hides each series' icon (from config), leaving its color swatch.
- Default
false
nameKey?string
The key in each legend item's data to look its label up by in config. * Defaults to the item's dataKey.
className?string
Merged with the part's classes.
ChartStyle
<style>
configChartConfig
The chart config whose colors it writes as --color-<key> variables.
idstring
The element's id.
ChartTooltip
ChartTooltipContent
<div>
hideIndicator?boolean
Hides each item's color indicator.
- Default
false
hideLabel?boolean
Hides the tooltip's label, the hovered point's.
- Default
false
indicator?"dashed" | "dot" | "line"
The color indicator's shape: a dot, a line or dashed.
- Type
"dashed" | "dot" | "line"- Default
"dot"
labelFormatter?(label: any, payload: TooltipPayload) → React.ReactNode
Formats the tooltip's label; its value is untyped, as in recharts 3.8.
- Type
(label: any, payload: TooltipPayload) → React.ReactNode- Parameters
label– anypayload– TooltipPayload- Returns
React.ReactNode
labelKey?string
The key in the data to read the label from, looked up in config.
nameKey?string
The key in each item's data to look its name up by in config.
className?string
Merged with the part's classes.
Related
Chart Tooltip
TooltipsThe default tooltip: a label, then each series with its dot.
Chart Tooltip without Indicator
TooltipsA tooltip with no color indicator beside the series.
Area Chart
Area chartsOne series as a smooth filled curve over six months.
Multiple Line Chart
Line chartsTwo series as lines on the same axes.
Multiple Bar Chart
Bar chartsTwo series grouped side by side for each month.
Chart Tooltip with Custom Label
TooltipsA tooltip whose label comes from the chart's config.