Skip to main content

Overview

The Tooltip class creates a contextual popup that displays information when hovering over chart elements. It automatically positions itself relative to a target element and includes a pointer.

Constructor

Tooltip.new(root, settings)
root
Root
required
The root element of the chart
settings
ITooltipSettings
Configuration settings for the tooltip

Settings

Content Settings

labelText
string
Text to use for the tooltip’s label.
labelHTML
string
HTML content to use for the tooltip’s label.
labelAriaLabel
string
Screen reader content for the label. Used with readerAnnounce. If set, its contents will be read by screen readers when the tooltip is shown.

Appearance Settings

pointerOrientation
'left' | 'right' | 'up' | 'down' | 'vertical' | 'horizontal'
Direction of the tooltip pointer.
  • vertical - Automatically points up or down based on position
  • horizontal - Automatically points left or right based on position
  • up, down, left, right - Fixed direction
getFillFromSprite
boolean
default:"true"
If true, will use the same fill color for its background as its tooltipTarget.
getFillGradientFromSprite
boolean
default:"false"
If true, will use the same fillGradient for its background as its tooltipTarget.
getLabelFillFromSprite
boolean
default:"false"
If true, will use the same fill color for label text as its tooltipTarget.
getStrokeFromSprite
boolean
default:"false"
If true, will use the same stroke color as its tooltipTarget.
autoTextColor
boolean
default:"true"
If true, tooltip will automatically adjust text color for better visibility on its background.

Position Settings

pointTo
IPoint
Screen coordinates the tooltip should point to. Object with x and y properties.
bounds
IBounds
Screen bounds to constrain the tooltip within. Prevents tooltip from going off-screen.
tooltipTarget
Sprite
Target element the tooltip is shown for.

Animation Settings

animationDuration
number
Duration in milliseconds for tooltip position changes (e.g., when jumping between targets).
animationEasing
(t: Time) => Time
Easing function for tooltip animations.

Behavior Settings

keepTargetHover
boolean
If true, the tooltip’s target element will be considered hovered when the mouse is over the tooltip itself.
readerAnnounce
boolean
default:"false"
If true, the tooltip contents will be read by screen readers when displayed or changed.

Properties

label

label
Label
The Label element for the tooltip (read-only).
const tooltip = Tooltip.new(root, {});
tooltip.label.set("fontSize", 14);

Methods

updateBackgroundColor()

Updates the tooltip’s background color based on its target element and color settings.
updateBackgroundColor(): void
This method is automatically called when the tooltip is shown or when tooltipTarget changes.

Events

Tooltip inherits all Container events and adds visibility tracking:
  • visible - Fired when tooltip visibility changes

Examples

Basic Tooltip

import { Tooltip } from "@amcharts/amcharts5";

const tooltip = Tooltip.new(root, {
  labelText: "Value: {value}"
});

series.set("tooltip", tooltip);

HTML Tooltip

const htmlTooltip = Tooltip.new(root, {
  labelHTML: `
    <div style="padding: 10px;">
      <strong>{category}</strong><br/>
      Value: {value}
    </div>
  `
});

Tooltip with Custom Styling

const styledTooltip = Tooltip.new(root, {
  labelText: "{category}: {value}",
  getFillFromSprite: false,
  autoTextColor: false
});

styledTooltip.get("background").setAll({
  fill: am5.color(0x000000),
  fillOpacity: 0.8
});

styledTooltip.label.setAll({
  fill: am5.color(0xffffff),
  fontSize: 12
});

Tooltip with Fixed Orientation

const fixedTooltip = Tooltip.new(root, {
  labelText: "Always points up",
  pointerOrientation: "up"
});

Animated Tooltip

const animatedTooltip = Tooltip.new(root, {
  labelText: "{value}",
  animationDuration: 300,
  animationEasing: am5.ease.out(am5.ease.cubic)
});

Accessible Tooltip

const accessibleTooltip = Tooltip.new(root, {
  labelText: "{category}: {value}",
  labelAriaLabel: "Category {category} has value {value}",
  readerAnnounce: true
});

Tooltip that Keeps Target Hovered

const interactiveTooltip = Tooltip.new(root, {
  labelHTML: '<a href="#">Click for details</a>',
  keepTargetHover: true
});

Using with Chart Elements

Most chart elements support tooltips through the tooltip setting:
// On a series
const series = chart.series.push(
  am5xy.ColumnSeries.new(root, {
    tooltip: Tooltip.new(root, {
      labelText: "{category}: {valueY}"
    })
  })
);

// On individual data items
series.columns.template.set("tooltip", Tooltip.new(root, {
  labelText: "Value: {valueY}"
}));

Pointer Positioning

The tooltip automatically positions its pointer based on:
  • pointerOrientation setting
  • Available space on screen
  • bounds constraints
  • The pointTo coordinates
For vertical and horizontal orientations, the tooltip intelligently chooses the best direction.

Build docs developers (and LLMs) love