Skip to content

Tooltip

Display interactive tooltips when hovering over the graph to show precise data values at any point.

Basic Usage

Enable tooltips by setting tooltip.enabled to true:

typescript
const graph = new Graph.Graph(
    "container",
    {
        tooltip: {
            enabled: true,
        },
    },
    lines,
);

Options

OptionTypeDefaultDescription
enabledbooleanfalseEnable/disable tooltip feature
mode"interpolated" | "nearest""nearest"How Y values are determined at cursor position
trackingLineTrackingLineOptionsSee belowVertical line that follows the cursor
contentTooltipContentOptionsSee belowTooltip box appearance
indicatorsTooltipIndicatorOptionsSee belowDots shown on lines at intersection
formatTooltipFormatOptionsSee belowValue formatting

Mode

The mode option determines how Y values are calculated when hovering:

ValueDescription
nearestSnaps to the nearest actual data point (default)
interpolatedSmoothly interpolates between data points

Nearest Mode (Default)

Snaps to actual data points with a smooth animation:

Interpolated Mode

Shows values at any position along the line:

Tracking Line Options

Configure the vertical line that follows the cursor:

OptionTypeDefaultDescription
showbooleantrueShow/hide tracking line
colourstring"rgba(0, 0, 0, 0.5)"Line color
widthnumber1Line width in pixels
style"solid" | "dashed""solid"Line style

Dashed Tracking Line

Content Options

Configure the tooltip box appearance:

OptionTypeDefaultDescription
showbooleantrueShow/hide tooltip box
backgroundColorstring"rgba(255, 255, 255, 0.95)"Background color
textColourstring"#333"Text color
fontSizenumber12Font size in pixels
paddingnumber8Inner padding in pixels
borderRadiusnumber4Corner radius in pixels

Indicator Options

Configure the dots shown on lines at the cursor position:

OptionTypeDefaultDescription
showbooleantrueShow/hide indicator dots
radiusnumber4Dot radius in pixels

Hidden Indicators

Format Options

Customize how values are displayed in the tooltip:

OptionTypeDefaultDescription
yValue(value: number, label: string) => string(y, label) => \${label}: ${y.toFixed(2)}``Custom value formatter

Custom Formatting

typescript
const graph = new Graph.Graph(
    "container",
    {
        tooltip: {
            enabled: true,
            format: {
                yValue: (value, label) => `${label}: $${value.toLocaleString()}`,
            },
        },
    },
    lines,
);

Complete Example

TypeScript Types

typescript
type TooltipOptions = {
    enabled?: boolean;
    mode?: "interpolated" | "nearest";
    trackingLine?: {
        show?: boolean;
        colour?: string;
        width?: number;
        style?: "solid" | "dashed";
    };
    content?: {
        show?: boolean;
        backgroundColor?: string;
        textColour?: string;
        fontSize?: number;
        padding?: number;
        borderRadius?: number;
    };
    indicators?: {
        show?: boolean;
        radius?: number;
    };
    format?: {
        yValue?: (value: number, label: string) => string;
    };
};

TIP

Tooltips work best with the legend enabled so users can identify which series each value belongs to.

Released under the ISC License.