ChartTooltip
The tooltip card of a chart point, rendered from pre-formatted strings, so it works on the server, inside the ChartInteraction island and inside a third-party renderer alike.
Import
import { ChartTooltip } from '@nizivo/charts/chart-tooltip';Static or interactive
Server. ChartTooltip has no 'use client' and imports no client module
(island-graph.test.ts in packages/charts/test/unit). It is only the card: showing it at a point,
placing it and announcing the point are the ChartInteraction island's job, which AreaChart and
BarChart render. The island imports this card, so a page with an interactive AreaChart or BarChart
ships it as part of the island's client graph (the island, this card and cx). How to choose.
Examples
Basic
Figma 03 Series=1: one row.
Tue, Oct 14
- This period
- $6,284
import type { JSX } from 'react';
import { ChartTooltip } from '@nizivo/charts/chart-tooltip';
export function ChartTooltipExample(): JSX.Element {
return (
<ChartTooltip
title="Tue, Oct 14"
rows={[{ label: 'This period', value: '$6,284', series: 'current' }]}
/>
);
}
Compare
Figma 03 Series=2: the comparison row and the change, up in text/success with its sign.
Tue, Oct 14
- This period
- $6,284
- Previous
- $4,910
+28.0% vs previous
import type { JSX } from 'react';
import { ChartTooltip } from '@nizivo/charts/chart-tooltip';
export function ChartTooltipCompareExample(): JSX.Element {
return (
<ChartTooltip
title="Tue, Oct 14"
rows={[
{ label: 'This period', value: '$6,284', series: 'current' },
{ label: 'Previous', value: '$4,910', series: 'previous' },
]}
delta={{ value: '+28.0%', label: 'vs previous', trend: 'up' }}
/>
);
}
Down
A fall reads text/critical, and the minus sign says so without colour.
Wed, Oct 15
- This period
- $3,980
- Previous
- $4,620
−13.9% vs previous
import type { JSX } from 'react';
import { ChartTooltip } from '@nizivo/charts/chart-tooltip';
export function ChartTooltipDownExample(): JSX.Element {
return (
<ChartTooltip
title="Wed, Oct 15"
rows={[
{ label: 'This period', value: '$3,980', series: 'current' },
{ label: 'Previous', value: '$4,620', series: 'previous' },
]}
delta={{ value: '−13.9%', label: 'vs previous', trend: 'down' }}
/>
);
}
Props
Server component. Props: ChartTooltipProps. Source: src/chart-tooltip/chart-tooltip.tsx.
| Name | Type | Default | Description |
|---|---|---|---|
delta | ChartTooltipDelta | – | |
rowsrequired | readonly ChartTooltipRow[] | – | One row per series; Figma's |
titlerequired | string | – | The point, for example "Tue, Oct 14" (Label/M Strong). |
- Also takes every
<div>attribute exceptchildren,title.
ChartTooltipRow: label (the series name), value (pre-formatted, Numeric/M, tabular) and
series (a ChartSeries, the swatch's colour role). ChartTooltipDelta: value (the change with
its sign, for example "+28.0%"), label (for example "vs previous") and trend
('up' | 'down' | 'flat'); their members are under Other exports. delta and
delta.label also accept undefined, so a computed value can be passed as it is under
exactOptionalPropertyTypes.
Other exports
ChartTooltipDeltatypeimport type { ChartTooltipDelta } from '@nizivo/charts/chart-tooltip'Name Type Default Description labelstring– For example "vs previous".
trendrequiredChartTrend"up""down""flat"– upreads text/success,downtext/critical,flattext/secondary.valuerequiredstring– The pre-formatted change with its sign, for example "+28.0%": the sign is the non-colour cue.
ChartTooltipPropstypeimport type { ChartTooltipProps } from '@nizivo/charts/chart-tooltip'The props of
ChartTooltip, listed above.ChartTooltipRowtypeimport type { ChartTooltipRow } from '@nizivo/charts/chart-tooltip'Name Type Default Description labelrequiredstring– The series name, for example "This period".
seriesrequiredChartSeries"current""previous""cat-1""cat-2""cat-3""other"– The colour role of the row's swatch.
valuerequiredstring– The pre-formatted value, for example "$6,284" (Numeric/M, tabular).
ChartTrendtypeimport type { ChartTrend } from '@nizivo/charts/chart-tooltip'The direction of a change, as
data-trend(contracts/vocabulary.json). Sparkline derives it from its data; ChartTooltip takes it fromdelta.trend(AreaChart derives that from the change).type ChartTrend = "up" | "down" | "flat"
Data attributes and slots
| Element | Attributes |
|---|---|
div.nz-chart-tooltip | data-slot="chart-tooltip" |
p.nz-chart-tooltip-title | The title |
dl.nz-chart-tooltip-rows | One div.nz-chart-tooltip-row per row: dt.nz-chart-tooltip-label (with span.nz-chart-tooltip-swatch[data-series], aria-hidden) and dd.nz-chart-tooltip-value |
p.nz-chart-tooltip-delta | data-trend: span.nz-chart-tooltip-change and span.nz-chart-tooltip-comparison |
The change reads text/success for up, text/critical for down and text/secondary for
flat.
CSS hooks
| Hook | Default | Read as |
|---|---|---|
--nz-chart-tooltip-halo | var(--nz-surface, var(--nz-bg-surface)) |
|
--nz-chart-tooltip-width | 12.5rem |
|
Layers: nz.components. Classes: .nz-chart-interaction, .nz-chart-interaction-columns, .nz-chart-interaction-dot, .nz-chart-interaction-point, .nz-chart-interaction-tip, .nz-chart-tooltip, .nz-chart-tooltip-change, .nz-chart-tooltip-delta, .nz-chart-tooltip-label, .nz-chart-tooltip-row, .nz-chart-tooltip-rows, .nz-chart-tooltip-swatch, .nz-chart-tooltip-title, .nz-chart-tooltip-value. Runtime variables: --nz-surface.
Tokens this stylesheet reads (28)
--nz-bg-surface, --nz-bg-surface-raised, --nz-border-strong, --nz-border-subtle, --nz-border-width-default, --nz-chart-cat-1, --nz-chart-cat-2, --nz-chart-cat-3, --nz-chart-neutral, --nz-chart-primary, --nz-distance-lift, --nz-duration-fast, --nz-easing-enter, --nz-elevation-3, --nz-font-body-m, --nz-font-label-m-strong, --nz-font-numeric-m, --nz-radius-full, --nz-radius-md, --nz-radius-sm, --nz-space-2, --nz-space-3, --nz-space-4, --nz-text-critical, --nz-text-primary, --nz-text-secondary, --nz-text-success, --nz-text-tertiary
--nz-chart-tooltip-width is the card's width (Figma: a fixed 200 px), and
--nz-chart-tooltip-halo the ring around the island's point dots: the surface behind the chart.
When the hook is unset, the ring takes the shared --nz-surface that @nizivo/react's
Card declares for its children (KpiTile and TrendCard are Cards, so a
tinted tile's halo is its own surface), else --nz-bg-surface. Charts read --nz-surface only if
it is there: without @nizivo/react on the page it is unset and the halo is --nz-bg-surface, and
@nizivo/charts does not depend on @nizivo/react (M42).
Accessibility
- The rows are a description list: each series name is a
<dt>, its value the<dd>. The swatch isaria-hidden. - The sign of the change ("+", "−") carries its direction without colour.
- Inside the island the whole card is
aria-hidden: the island's polite live region speaks the point, and the chart's data table carries every value. Rendered on its own, the card is ordinary text.
Figma
Chart Tooltip, 7275:13303: Series=1 7275:13304 (200 × 75) and Series=2 7275:13310
(200 × 133, with the delta row). "Follows the crosshair; flips side near edges. Fade + 4px travel,
duration/fast. Values in Numeric/M (tabular)." The Area and Bar hover variants use a duplicate set,
747:287, which is on no page; code follows 7275:13303. Notes: docs/figma/03-data-viz.md §4.2.
Legend
The series key of a chart, rendered on the server as a list. Its mark follows the series (a line, a dashed line or a dot); the vertical form adds values and shares, as the donut's legend does.
Patterns
Domain compositions built only from the published packages, for you to copy into your app and change. The source is MIT, not Apache-2.0, so a copy you edit owes no change notice.