DitherCharts

Tooltip

Updated

Every chart takes a tooltip prop: an object that sets the header over the rows, how each row marks its series, a unit after each value, a total row, and the point the tooltip opens on before anyone hovers. Leave it out and the tooltip shows the x label over one row per series, each marked with a square in the series' pattern.

Usage

A stacked bar chart whose tooltip drops the date and adds a unit and a total:

const chartData = [
  { date: "Jul 15", running: 450, swimming: 300 },
  { date: "Jul 16", running: 380, swimming: 420 },
]

const chartConfig = {
  running: { label: "Running" },
  swimming: { label: "Swimming" },
} satisfies ChartConfig

<BarChart
  data={chartData}
  config={chartConfig}
  xKey="date"
  label="Running and swimming by day"
  stack="stacked"
  tooltip={{ hideLabel: true, unit: "kcal", total: true }}
/>

Options

Tooltip options
PropTypeDefaultDescription
labelType stringDefault –Fixed text over the rows, in place of the x label.
labelKeyType stringDefault –The row key whose value heads the tooltip in place of the x label, e.g. a long date.
indicatorType "dot" | "line" | "dashed" | "none"Default "dot" (a square)How each row marks its series, in the series' pattern.
hideLabelType booleanDefault falseLeave out the x label over the rows.
hideIndicatorType booleanDefault falseLeave out the rows' indicators.
unitType stringDefault –Text after every value, e.g. "kcal".
totalType booleanDefault falseA row under the series that sums them.
defaultIndexType numberDefault –The x position whose tooltip shows at rest; the cursor takes over while it is on the chart.

Behavior

The tooltip is drawn in the charts' 3x5 bitmap font, in ink on paper. On a chart with several series, the row under the cursor is inverted. A config entry's icon takes the place of its row's indicator.

With defaultIndex, the tooltip shows at rest. The pointer or the arrow keys take over, and Escape returns it to the resting point.

The tooltip is decorative. Screen readers get each chart's data table and its announcements as the cursor moves.

See all 9 tooltip examples