Hooks
Hooks are named extension points registered on a chart instance with
addHook(). There is currently one
hook type.
TooltipHookState and TooltipHookItem, named below for clarity, are not
exported by the package. TypeScript still checks the callback correctly when you
call addHook("tooltip:items", callback). You just can’t import these names to
write the callback’s type separately.
tooltip:items
Section titled “tooltip:items”Type: (state: TooltipHookState) => TooltipHookItem[]
Called every time the tooltip is shown, for every chart type. Return additional tooltip items to append to the tooltip. See the tooltip guide for a worked example.
Argument: TooltipHookState
Section titled “Argument: TooltipHookState”| Property | Type | Notes |
|---|---|---|
xAxisValue |
number | string | null |
Set in line charts. null in bar charts. |
yAxisValue |
number | string | null |
Set in bar charts, for the value shown on the category axis. null in line charts. |
groupValue |
string | null |
Currently always null. No chart type sets it. |
data |
DataList |
The data points currently shown in the tooltip, not the full data array. |
Return: TooltipHookItem[]
Section titled “Return: TooltipHookItem[]”An array of:
| Property | Type | Notes |
|---|---|---|
key |
string |
The item’s label. |
value |
string | number |
The item’s value. A number is formatted with the axis’s extended formatter; NaN is replaced with tooltip.undefinedLabel. |
Error handling
Section titled “Error handling”If a hook function throws, the error is logged to the console
(Hook "tooltip:items" failed) and that hook’s result is skipped. Other
registered hooks still run.