logo

G2

  • Chart Gallery
  • Docs
  • Examples
  • Theme
  • Ecosystem
  • Productsantv logo arrow
  • 5.3.3
  • Get Started
  • Introduction
    • What is G2
    • Using in Frontend Frameworks
    • Experimental Spec API
  • Chart API
  • Core Concepts
    • Chart
      • Components of G2 Charts
      • How to Use Charts
    • Mark
      • Overview
      • area
      • box
      • boxplot
      • cell
      • chord
      • density
      • gauge
      • heatmap
      • image
      • interval
      • line
      • lineX
      • lineY
      • link
      • liquid
      • sunburst
      • point
      • polygon
      • range
      • rangeX
      • rangeY
      • rect
      • shape
      • text
      • vector
      • connector
      • wordCloud
    • View
    • Data
      • Overview
      • custom
      • ema
      • fetch
      • filter
      • fold
      • inline
      • join
      • kde
      • log
      • map
      • pick
      • rename
      • slice
      • sort
      • sortBy
    • Encode
    • Scale
      • Overview
      • band
      • linear
      • log
      • ordinal
      • point
      • quantile
      • quantize
      • sqrt
      • threshold
      • time
      • pow
    • Transform
      • Overview
      • bin
      • binX
      • diffY
      • dodgeX
      • flexX
      • group
      • groupColor
      • groupX
      • groupY
      • jitter
      • jitterX
      • jitterY
      • normalizeY
      • pack
      • sample
      • select
      • selectX
      • selectY
      • sortColor
      • sortX
      • sortY
      • stackEnter
      • stackY
      • symmetryY
    • Coordinate
      • Overview
      • fisheye
      • parallel
      • polar
      • theta
      • transpose
      • radial
      • cartesian3D
      • helix
    • Style
    • Animate
      • Overview
      • fadeIn
      • fadeOut
      • growInX
      • growInY
      • morphing
      • pathIn
      • scaleInX
      • scaleInY
      • scaleOutX
      • scaleOutY
      • waveIn
      • zoomIn
      • zoomOut
    • State
    • Interaction
      • Overview
      • brushAxisHighlight
      • brushHighlight
      • brushXHighlight
      • brushYHighlight
      • brushFilter
      • brushXFilter
      • brushYFilter
      • chartIndex
      • elementHighlight
      • elementHighlightByColor
      • elementHighlightByX
      • elementSelect
      • elementSelectByColor
      • elementSelectByX
      • legendFilter
      • legendHighlight
      • poptip
      • scrollbarFilter
      • sliderFilter
      • fisheye
    • Composition
      • Overview
      • facetCircle
      • facetRect
      • repeatMatrix
      • spaceFlex
      • spaceLayer
      • timingKeyframe
    • Theme
      • Overview
      • academy
      • classic
      • classicDark
    • Events
    • Color Mapping
  • Chart Component
    • Title
    • Axis
    • Legend
    • Scrollbar
    • Slider
    • Tooltip
    • Data Label
  • Extra Topics
    • Graph
      • forceGraph
      • pack
      • sankey
      • tree
      • treemap
    • Geo
      • geoPath
      • geoView
    • 3D
      • Draw 3D Chart
      • point3D
      • line3D
      • interval3D
      • surface3D
    • Plugin
      • renderer
      • rough
      • lottie
      • a11y
    • Package on demand
    • Set pattern
    • Server-Side Rendering (SSR)
    • Spec Function Expression Support (Available in 5.3.0)
  • Whats New
    • New Version Features
    • Migration from v4 to v5
  • Frequently Asked Questions (FAQ)

Tooltip

Previous
Slider
Next
Data Label

Resources

Ant Design
Galacea Effects
Umi-React Application Framework
Dumi-Component doc generator
ahooks-React Hooks Library

Community

Ant Financial Experience Tech
seeconfSEE Conf-Experience Tech Conference

Help

GitHub
StackOverflow

more productsMore Productions

Ant DesignAnt Design-Enterprise UI design language
yuqueYuque-Knowledge creation and Sharing tool
EggEgg-Enterprise-class Node development framework
kitchenKitchen-Sketch Tool set
GalaceanGalacean-互动图形解决方案
xtechLiven Experience technology
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

Overview

Tooltip is one of the core components of chart interaction, used to dynamically display detailed information about data points, helping users quickly understand the values, categories, or other dimensional information in specific areas of the chart. It can dynamically show related data information when the mouse hovers, clicks, or moves to a chart element (such as bars in a bar chart or data points in a line chart).

  • Display detailed information: Tooltip can show detailed information about data points, such as specific values, percentages, or other related attributes. This helps users understand the data more deeply.
  • Improve readability: In complex visualizations, Tooltip can help users more easily identify and understand data points. For example, in scatter plots where data points are dense, Tooltip can display detailed information about specific points without having to hover over each point.
  • Enhance interactivity: Tooltip can enhance the interactivity of visualizations. Users can view more information by hovering or clicking on data points, making the visualization more dynamic and engaging.
  • Highlight key information: Tooltip can be used to highlight key information. For example, in time series charts, you can use Tooltip to display important events or mutations at specific time points.
  • Support multiple trigger methods: Can be triggered through mouse hover, click, touch and other events.

Components

tooltip

Usage

chart.options({
type: 'interval',
tooltip: {
title: 'name', // Title
items: ['genre'], // Data items
},
});

And combined with view.interaction.tooltip to configure tooltip rendering and additional settings.

chart.options({
type: 'view',
interaction: {
tooltip: { series: true },
},
});

When there is only one mark in the view, configuring tooltip rendering and additional settings through mark.interaction.tooltip is also possible.

chart.options({
type: 'line',
interaction: {
tooltip: { series: true },
},
});

If you want to disable tooltip display, you can turn it off with the following configuration.

chart.options({
type: 'interval',
tooltip: false,
});

If you want the chart to have no tooltip interaction, you can achieve this through chart.interaction.

chart.options({
type: 'view',
interaction: { tooltip: false },
});

Try it out

Configuration Options

Configuration options are divided into two parts

  • tooltip is a UI component in G2 used to display detailed information about data points. When users hover over a data point in the chart, tooltip displays related information about that data point, such as coordinate values, measure values, etc.

  • interaction.tooltip is part of G2's interaction mechanism, belonging to the interaction module. It's a built-in interactive behavior used to enhance tooltip functionality, especially in certain specific interactive scenarios (such as dynamically showing or hiding tooltips).

tooltip and interaction.tooltip are configurations in two different dimensions, but they can be confusing. Here are their core differences:

Featuretooltipinteraction.tooltip
ResponsibilityDefine tooltip content, style and basic behaviorDefine tooltip behavior in interactive scenarios
ConfigurationConfigured through chart.tooltip()Enabled or customized through chart.interaction()
ScopeGlobal effect, affects the entire chartBound to specific interactive behaviors
Typical UseSet tooltip fields, styles, content, etc.Control dynamic display/hide or other interactive logic

tooltip

PropertyDescriptionTypeDefaultApplicable to
titleSet tooltip title content: If value is a data field name, it will display the value of that field in the data. If the field doesn't exist in the data, use the value as title. See title configurationtitle
nodeTitleSet node title attribute for composite chart tooltip titlestitleComposite charts like Sankey
linkTitleSet link title attribute for composite chart tooltip titlestitleComposite charts like Sankey
itemsSpecify fields displayed in tooltip. Different charts have different default field lists. Works better when used with channel configuration. See items configurationitems
nodeItemsSet node items attribute for composite chart tooltipitemsComposite charts like Sankey
linkItemsSet link items attribute for composite chart tooltipitemsComposite charts like Sankey

title

title is a field used to display the main title of the currently hovered data point, typically used to represent the category or contextual information that the data point belongs to.

title can be directly written as a fixed string to display, or a method to dynamically get the title from data

chart.options({
type: 'interval',
tooltip: {
title: (d) => (d.sold > 150 ? 'high' : 'low'), // Set title
},
});

When you don't need to customize the title, you can directly declare tooltip as an array, in which case the title will use default configuration:

chart.options({
type: 'interval',
tooltip: ['genre', 'sold'],
});

The complete title structure is as follows:

Sub-configuration NameTypeFunction Description
channelstringDefine the channel for generating title
fieldstringDefine the field for generating title
valuestringTitle value
valueFormatterstring | FunctionFormat title
  • Field

Their values can come from original data, specified by string or title.field.

chart.options({
tooltip: {
title: 'sold',
items: ['genre'],
},
});
// Equivalent to
chart.options({
tooltip: {
title: { field: 'sold' },
items: [{ field: 'genre' }],
},
});
  • Channel

Their values can come from channel values, specified through title.channel, often used for charts that generate new channels using mark.transform.

chart.options({
tooltip: {
title: { channel: 'x' },
items: [{ channel: 'y' }],
},
});
  • Formatting

You can specify the display of title value through title.valueFormatter. title.valueFormatter can be a function or a string supported by d3-format.

chart.options({
tooltip: {
title: {field: 'sold', valueFormatter: (sold) => sold.toUpperCase()},
items: [{ channel: 'y', valueFormatter: '.0%' }],
},
});
  • Personalized Configuration

Of course, callbacks are also provided for title to achieve maximum personalized configuration capability.

chart.options({
tooltip: {
title: (datum, index, data, column) => ({
value: `<span style="color: #00ff00; font-style: italic;">${datum.letter}</span>`,
custom: "..."
}),
items: [
(datum, index, data, column) => ({
color: datum.sold > 150 ? 'red' : 'blue', // Specify item color
name: index === 0 ? datum.genre : `${datum.genre} ${data[index].genre}`, // Specify item name
value: column.y.value[index], // Use y channel value
custom: "..."
}),
],
},
});

The items return value can be used as parameters for interaction.tooltip.render, where you can set custom parameters. See Custom Render Content

Composite Chart Configuration

When configuring tooltip.title for composite charts, you need to configure nodes and links separately

({
tooltip: {
nodeTitle: (d) => d.key,
linkTitle: (d) => 'link',
},
});

items

items is a key attribute in tooltip configuration. items is an array representing the content of each item in the tooltip. Each item typically corresponds to a data field or a graphical element (such as a bar in a bar chart, a point in a line chart, etc.). By customizing items, you can flexibly control the display content of tooltips, including name, value, color and other information.

The complete item structure is as follows:

Sub-configuration NameTypeFunction Description
colorstringMarker color
fieldstringDefine the field for generating item
namestringItem name
valuestringItem value
channelstringDefine the channel for generating item value
valueFormatterstring | FunctionFormat item

The value, channel, and valueFormatter properties of items are configured the same way as title. For detailed configuration, please refer to title

Name

You can conveniently modify the name of item in tooltip through name, and use channel to match the corresponding entry in the chart.

chart.options({
tooltip: {
items: [
{name: 'Zhang San', channel: 'y1'},
{name: 'Li Si', channel: 'y2'},
],
},
});

Color

tooltip will automatically assign colors to tooltip item based on chart content, but in practical applications, you may need to specify certain colors according to some rules. In this case, you can configure through the color property. Use channel to match the corresponding entry in the chart.

chart.options({
tooltip: {
items: [
{color: 'pink', channel: 'y1'},
{color: '#f00', channel: 'y2'},
],
},
});

Composite Chart Configuration

When configuring tooltip.items for composite charts, you need to configure nodes and links separately

({
tooltip: {
nodeItems: [
(datum, index, data, column) => {
return {
color: 'red', // Specify item color
name: 'Node', // Specify item name
value: d.key, // Use y channel value
content: 'Node custom attribute',
};
},
],
linkItems: [
(datum, index, data, column) => {
return {
color: 'red', // Specify item color
name: 'Link', // Specify item name
value: `${d.source.key}-${d.target.key}`, // Use y channel value
content: 'Link custom attribute',
};
},
],
},
});

interaction.tooltip

PropertyDescriptionTypeDefaultApplicable to
bodyWhether to show tooltipbooleantrue
boundingControl tooltip display boundary, position will be automatically adjusted when exceeded{ x: number, y: number, width: number, height: number }Chart area size
cssSet tooltip CSS stylescss-
crosshairsConfigure crosshair stylecrosshairsSee crosshairs
disableNativeDisable native pointerover and pointerout events, needs to be set to true when customizing tooltip interactionbooleanfalse
enterableWhether tooltip allows mouse entrybooleanfalse
facetWhether it's a facet chart tooltipbooleanfalseFacet composite charts
filterItem filter(d: TooltipItemValue) => any-
groupNameWhether to use groupNamebooleantrue
leadingWhether to update tooltip at the beginning of time intervalbooleantrue
markerConfigure marker stylemarkerSee marker
markerTypeControls marker style when showing tooltip, whether it's hollow or solid. Default is solid, set to 'hollow' for hollow'hollow' | undefinedundefined
mountSpecify tooltip mount nodestring | HTMLElementChart container
positionSet fixed display position of tooltip relative to data point'top' | 'bottom' | 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right''right-bottom'
offsetOffset in position direction[number, number][10, 10]
renderCustom render tooltip content(event, options) => HTMLElement | string-
seriesWhether it's a series element tooltipbooleanfalseMulti-line, multi-bar charts
sharedWhether elements with same x share tooltipbooleanfalse
sortItem sorter(d: TooltipItemValue) => any-
trailingWhether to update tooltip at the end of time intervalbooleanfalse
waitTime interval for tooltip update in millisecondsnumber50

crosshairs

crosshairs is an auxiliary line feature for tooltips, used to mark the precise position of current data points in charts. It's mainly used for continuous graphs like line charts and area charts. Usually presented as horizontal or vertical reference lines to help users visually locate data more intuitively.

Additionally, styles set through prefixes crosshairsX and crosshairsY have higher priority than crosshairs and will override the latter.

PropertyDescriptionTypeDefaultRequired
crosshairsWhether to show crosshairsbooleantrue
crosshairsStrokeCrosshair colorstring-
crosshairsStrokeOpacityCrosshair transparencynumber-
crosshairsLineWidthCrosshair stroke widthnumber-
crosshairsLineDashCrosshair dash configuration, first value is dash segment length, second is interval[number,number]-
crosshairsOpacityOverall crosshair transparencynumber-
crosshairsShadowColorCrosshair shadow colorstring-
crosshairsShadowBlurCrosshair shadow blur coefficientnumber-
crosshairsShadowOffsetXCrosshair shadow horizontal offsetnumber-
crosshairsShadowOffsetYCrosshair shadow vertical offsetnumber-
crosshairsCursorCrosshair cursor stylestringdefault
crosshairsXWhether to show horizontal crosshairbooleanfalse
crosshairsXStrokeHorizontal crosshair colorstring-
crosshairsXStrokeOpacityHorizontal crosshair transparencynumber-
crosshairsXLineWidthHorizontal crosshair stroke widthnumber-
crosshairsXLineDashHorizontal crosshair dash configuration[number,number]-
crosshairsXOpacityOverall horizontal crosshair transparencynumber-
crosshairsXShadowColorHorizontal crosshair shadow colorstring-
crosshairsXShadowBlurHorizontal crosshair shadow blur coefficientnumber-
crosshairsXShadowOffsetXHorizontal crosshair shadow horizontal offsetnumber-
crosshairsXShadowOffsetYHorizontal crosshair shadow vertical offsetnumber-
crosshairsXCursorHorizontal crosshair cursor stylestringdefault
crosshairsYWhether to show vertical crosshairbooleantrue
crosshairsYStrokeVertical crosshair colorstring-
crosshairsYStrokeOpacityVertical crosshair transparencynumber-
crosshairsYLineWidthVertical crosshair stroke widthnumber-
crosshairsYLineDashVertical crosshair dash configuration[number,number]-
crosshairsYOpacityOverall vertical crosshair transparencynumber-
crosshairsYShadowColorVertical crosshair shadow colorstring-
crosshairsYShadowBlurVertical crosshair shadow blur coefficientnumber-
crosshairsYShadowOffsetXVertical crosshair shadow horizontal offsetnumber-
crosshairsYShadowOffsetYVertical crosshair shadow vertical offsetnumber-
crosshairsYCursorVertical crosshair cursor stylestringdefault
chart.options({
interaction: {
legendFilter: false,
elementPointMove: true,
tooltip: {
crosshairs: true, // Enable crosshairs
crosshairsStroke: 'red', // Crosshair color is red
crosshairsYStroke: 'yellow', // Vertical crosshair color set separately to yellow
crosshairsLineDash: [4, 4], // Crosshair dashed style
markerType: 'hollow', // Tooltip marker is hollow
},
},
});

marker

PropertyDescriptionTypeDefaultRequired
markerWhether to show markerbooleantrue
markerFillMarker fill colorstring-
markerFillOpacityMarker fill transparencynumber-
markerStrokeMarker stroke colorstring-
markerStrokeOpacityMarker stroke transparencynumber-
markerLineWidthMarker stroke widthnumber-
markerLineDashMarker stroke dash configuration, first value is dash segment length, second is interval[number,number]-
markerOpacityOverall marker transparencynumber-
markerShadowColorMarker shadow colorstring-
markerShadowBlurMarker shadow blur coefficientnumber-
markerShadowOffsetXMarker shadow horizontal offsetnumber-
markerShadowOffsetYMarker shadow vertical offsetnumber-
markerCursorMarker cursor stylestringdefault
chart.options({
interaction: {
tooltip: {
marker: true,
markerType: 'hollow', // Tooltip marker is hollow
markerStroke: 'yellow',
markerLineWidth: 2,
markerLineDash: [4, 4],
},
},
});

Set Styles

The tooltip cssStyle configuration option allows direct customization of tooltip appearance through CSS styles, enabling quick visual customization of tooltips to adapt to different themes or interaction scenarios.

tooltip

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'interval',
data: {
type: 'fetch',
value:
'https://gw.alipayobjects.com/os/bmw-prod/f129b517-158d-41a9-83a3-3294d639b39e.csv',
format: 'csv',
},
encode: {
x: 'state',
y: 'population',
color: 'age',
},
transform: [
{ type: 'sortX', by: 'y', reverse: true, reducer: 'sum', slice: 6 },
{ type: 'dodgeX' },
],
legend: false,
interaction: {
tooltip: {
shared: true,
mount: 'body',
css: {
'.g2-tooltip': {
background: '#eee',
'border-radius': ' 0.25em !important',
},
'.g2-tooltip-title': {
'font-size': '20px',
'font-weight': 'bold',
'padding-bottom': '0.25em',
},
'.g2-tooltip-list-item': {
background: '#ccc',
padding: '0.25em',
margin: '0.25em',
'border-radius': '0.25em',
},
'.g2-tooltip-list-item-name-label': {
'font-weight': 'bold',
'font-size': '16px',
},
'g2-tooltip-list-item-marker': {
'border-radius': '0.25em',
width: '15px',
height: '15px',
},
'.g2-tooltip-list-item-value': {
'font-weight': 'bold',
'font-size': '16px',
},
},
},
},
});
chart.render();

Try it out

Custom Render Content

Sometimes the built-in Tooltip cannot meet requirements. In this case, you can render custom tooltips through the render function in mark.interaction.tooltip.render or view.interaction.tooltip.render.

The render function accepts an event object event and tooltip data tooltipData, returning a string or DOM object. Where event is a mouse object thrown by @antv/g, and tooltipData is title and items data declared through mark.tooltip. If the return value is a string, it will be used as innerHTML of the tooltip container, otherwise the return value will be mounted. A tooltip render function definition looks like this:

function render(event, tooltipData) {
const { title, items } = tooltipData;
return `<div></div>`;
}

Here's a simple example:

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart
.interval()
.data({
type: 'fetch',
value:
'https://gw.alipayobjects.com/os/bmw-prod/fb9db6b7-23a5-4c23-bbef-c54a55fee580.csv',
})
.transform([{ type: 'sortX', by: 'y', reverse: true }])
.encode('x', 'letter')
.encode('y', 'frequency')
.interaction('tooltip', {
// render callback method returns innerHTML or DOM
render: (event, { title, items }) => `<div>
<h3 style="padding:0;margin:0">${title}</h3>
<ul>${items.map(
(d) =>
`<li><span style="color: ${d.color}">${d.name}</span> ${d.value}</li>`,
)}</ul>
</div>`,
});
chart.render();

Events

The chart.on() method registers the specified listener to the chart. When the object triggers the specified event, the specified callback function will be executed.

Here's how to configure tooltip show/hide events:

chart.on('tooltip:show', (event) => {
console.log(event.data.data);
});
chart.on('tooltip:hide', () => {
console.log('hide');
});

Try it out

Examples

title

mark.tooltip({
title: 'name', // Field
});
mark.tooltip({
title: (d) => (d.value > 100 ? d.name : d.age), // Transform
});

item

// Single field
mark.tooltip('a');
mark.tooltip({ field: 'a' });
// Single channel
mark.tooltip({ channel: 'y' });
// Transform
mark.tooltip((d) => (d.value > 100 ? d.name : d.age));
// Formatting
mark.tooltip({ channel: 'y', valueFormatter: (d) => d.toFixed(1) });
// d3-format supported strings
// https://github.com/d3/d3-format
mark.tooltip({ channel: 'y', valueFormatter: '~s' });
// Complete information
mark.tooltip({ name: 'name', color: 'red', value: 'color' });
// Callback
mark.tooltip(
(
d, // Each data item
index, // Index
data, // Complete data
column, // Channel
) => ({
value: `${column.y.value[index]} - ${column.y1.value[index]}`,
}),
);
// Multiple items
mark.tooltip({ channel: 'y' }).tooltip({ channel: 'x' });

title + item

mark.tooltip({
title: 'a',
items: [{ channel: 'x' }, { channel: 'y' }],
});

How to use additional data from data as parameters for custom render function

The render function provides powerful personalized configuration capabilities. By configuring the return parameters of the tooltip.render function, you can customize the input parameters for interaction.tooltip.render

chart.options({
tooltip: {
items: [
(datum, index, data, column) => ({
color: datum.sold > 150 ? 'red' : 'blue', // Specify item color
name: index === 0 ? datum.genre : `${datum.genre} ${data[index].genre}`, // Specify item name
value: column.y.value[index], // Use y channel value
custom1: 'Custom parameter 1',
custom2: 'Custom parameter 2'
}),
],
},
interaction: {
tooltip: {
// render callback method returns innerHTML or DOM
render: (event, { title, items }) => {
return `<div>
<h3 style="padding:0;margin:0">${title}</h3>
<ul>${items.map(
({ color, name, value, custom1, custom2 }) => "..."
)}</ul>
</div>`
}
}
}
});

Manual Control Show/Hide

For non-series marks like Interval, Point, the control method is as follows:

// Bar charts, point charts, etc.
chart
.interval()
.data([
{ genre: 'Sports', sold: 275 },
{ genre: 'Strategy', sold: 115 },
{ genre: 'Action', sold: 120 },
{ genre: 'Shooter', sold: 350 },
{ genre: 'Other', sold: 150 },
])
.encode('x', 'genre')
.encode('y', 'sold')
.encode('color', 'genre');
chart.render().then((chart) =>
chart.emit('tooltip:show', {
offsetX: 10, // Position relative to plot area
offsetY: 20, // Position relative to plot area
data: {
data: { genre: 'Sports' }, // Will find matching data from original data
},
}),
);

For series marks like Line, Area, the control method is as follows:

chart
.line()
.data({ type: 'fetch', value: 'data/aapl.csv' })
.encode('x', 'date')
.encode('y', 'close');
// Pick based on data
chart.render((chart) =>
chart.emit('tooltip:show', {
data: {
data: { x: new Date('2010-11-16') },
},
}),
);
// Pick based on pixels
chart.render((chart) =>
chart.emit('tooltip:show', {
offsetX: 200,
offsetY: 200,
}),
);

Hide method:

chart.emit('tooltip:hide');

Enable/Disable Interaction

chart.emit('tooltip:disable'); // Disable tooltip
chart.emit('tooltip:enable'); // Enable interaction

Set Crosshairs

By default, crosshairsY is enabled and crosshairsX is disabled. So to enable crosshairs, there are two ways:

  1. Set crosshairs to true.
chart.interaction('tooltip', {
crosshairs: true, // Enable crosshairs
crosshairsXStroke: 'red', // Set X-axis crosshair color to 'red'
crosshairsYStroke: 'blue', // Set Y-axis crosshair color to 'blue'
});
  1. Set crosshairsX to true.
chart.interaction('tooltip', {
crosshairsX: true, // Enable crosshairsX
crosshairsXStroke: 'red', // Set X-axis crosshair color to 'red'
crosshairsYStroke: 'blue', // Set Y-axis crosshair color to 'blue'
});

crosshairsX has higher priority than crosshairs.

example

Set Tooltip Point to Hollow Circle

chart.interaction('tooltip', {
markerType: 'hollow', // Set tooltip point style to hollow circle
});
example

How to use supplementary attributes from data to implement custom tooltip display for composite charts like Sankey?

Similar to the method for customizing tooltip interaction for general Mark, first return custom attributes in the chart's tooltip.render, then use them in interaction.render.

({
type: 'sankey',
data: {
value: {
nodes: [
{ id: 'a', key: 'Home', des: 'Node custom attribute' },
{ id: 'b', key: 'Page1', des: 'Node custom attribute' },
{ id: 'b_1', key: 'Page1', des: 'Node custom attribute' },
{ id: 'c', key: 'Page2', des: 'Node custom attribute' },
{ id: 'c_1', key: 'Page2', des: 'Node custom attribute' },
{ id: 'd', key: 'Page3', des: 'Node custom attribute' },
{ id: 'd_1', key: 'Page3', des: 'Node custom attribute' },
],
links: [
{ source: 'a', target: 'b', value: 100 },
{ source: 'b', target: 'c', value: 80 },
{ source: 'b', target: 'd', value: 20 },
{ source: 'c', target: 'b_1', value: 80 },
{ source: 'b_1', target: 'c_1', value: 40 },
{ source: 'b_1', target: 'd_1', value: 40 },
],
},
transform: [
{
type: 'custom',
callback: (data) => ({
nodes: data.nodes,
links: data.links,
}),
},
],
},
tooltip: {
nodeItems: [
(datum, index, data, column) => {
return {
content: d.des,
};
},
],
linkItems: [
(datum, index, data, column) => {
return {
color: 'red', // Specify item color
name: 'Link', // Specify item name
value: `${d.source.key}-${d.target.key}`, // Use y channel value
content: 'Link custom attribute',
};
},
],
},
layout: {
nodeId: (d) => d.id,
nodeAlign: 'center',
nodePadding: 0.03,
iterations: 25,
},
style: {
labelSpacing: 3,
labelFontWeight: 'bold',
linkFillOpacity: 0.2,
linkFill: '#3F96FF',
},
interaction: {
tooltip: {
render: (e, { items, title }) => {
return `<div>${items[0].content}</div>`;
},
},
},
});