logo

G2

  • Chart Gallery
  • Docs
  • Examples
  • Theme
  • Ecosystem
  • Productsantv logo arrow
  • 5.4.7
  • Get Started
  • Introduction
    • What is G2
    • Using in Frontend Frameworks
    • Experimental Spec API
  • Chart API
  • Core Concepts
    • G2's complete configuration system
    • Chart
      • Components of G2 Charts
      • Chart Lifecycle
    • Mark
      • Overview
      • area
      • box
      • boxplot
      • cell
      • chord
      • density
      • gauge
      • heatmap
      • image
      • interval
      • line
      • lineX
      • lineY
      • link
      • liquid
      • sunburst
      • beeswarm
      • 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
      • elementHoverScale
      • elementHighlightByX
      • elementSelect
      • elementSelectByColor
      • elementSelectByX
      • legendFilter
      • legendHighlight
      • poptip
      • scrollbarFilter
      • sliderFilter
      • sliderWheel
      • fisheye
    • Composition
      • Overview
      • facetCircle
      • facetRect
      • repeatMatrix
      • spaceFlex
      • spaceLayer
      • timingKeyframe
    • Theme
      • Overview
      • academy
      • classic
      • classicDark
    • Event Handling
    • 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)

elementHoverScale

Previous
elementHighlightByColor
Next
elementHighlightByX

Resource

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

Community

Ant Financial Experience Tech
seeconfSEE Conf-Experience Tech Conference
weavefoxWeaveFox-AI Developer Community

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-Interactive solution
weavefoxWeaveFox-AI Coding Assistant
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

Overview

The elementHoverScale interaction targets chart elements. When the mouse hovers over an element, it scales up and adds a shadow effect for stronger visual feedback. This interaction is particularly suitable for pie charts, donut charts, and other scenarios where individual elements need to be highlighted.

  • Trigger: Mouse hover over an element
  • End: Mouse leaves the element
  • State Change: The hovered element becomes active
  • Visual Effect: Element scales up, increases in z-index, and adds shadow
hover-scale-piehover-scale-donuthover-scale-group

Usage

There are two ways to configure the elementHoverScale interaction:

First method: pass a boolean to enable/disable the interaction with default settings.

({
type: 'interval',
interaction: { elementHoverScale: true }, // use default configuration
});

Second method: pass a configuration object to customize the interaction.

({
type: 'interval',
interaction: {
elementHoverScale: {
scale: 1.1,
shadow: true,
shadowColor: 'rgba(0, 0, 0, 0.5)',
},
},
});

Configuration Level

The interaction can be configured at the Mark level:

({
type: 'interval',
interaction: { elementHoverScale: true },
});

Or at the View level. Interactions declared on the view are passed to child marks. If a child mark declares the same interaction, they are merged; otherwise, the view-level interaction does not affect the child.

({
type: 'view',
interaction: { elementHoverScale: true },
});

Configuration

PropertyDescriptionTypeDefault ValueRequired
scaleScale factor on hovernumber1.04
shadowWhether to show shadowbooleantrue
shadowColorShadow colorstring'rgba(0, 0, 0, 0.4)'
shadowBlurShadow blur radiusnumber10
shadowOffsetXHorizontal shadow offsetnumber0
shadowOffsetYVertical shadow offsetnumber2
zIndexz-index when hoverednumber10
delayDelay before resetting on leavenumber60 (milliseconds)
createGroupCustom grouping functionfunction(d) => d (group by data)

Configuration Details

scale

Controls the scale factor when hovering. A value of 1.04 means the element scales to 104% of its original size. Scaling defaults to center origin.

shadow

Whether to add a shadow effect on hover. The shadow enhances visual hierarchy.

createGroup

Custom grouping function to control which elements should respond to hover together. By default, each element responds independently.

// Example: group by category field
createGroup: (data) => data.category;

Events

Listening to Events

Supported events:

  • element:hoverscale - triggered when an element is hovered and scaled
  • element:unhoverscale - triggered when the hover scale is removed
chart.on('element:hoverscale', (e) => {
console.log(e.data.data); // data of the hovered element
console.log(e.data.group); // array of grouped element data
console.log(e.nativeEvent); // native event object
});
chart.on('element:unhoverscale', (e) => {
console.log(e.nativeEvent);
});

Triggering Interaction

Supported trigger events:

  • element:hoverscale - trigger element scale
  • element:unhoverscale - cancel element scale
chart.emit('element:hoverscale', {
data: { data: { category: 'A', value: 100 } },
});
chart.emit('element:unhoverscale', {});

Examples

Pie Chart Hover Scale

The most common use case for elementHoverScale is in pie charts to highlight the hovered sector:

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
autoFit: true,
});
chart.options({
type: 'interval',
height: 400,
data: [
{ item: 'Case 1', count: 40, percent: 0.4 },
{ item: 'Case 2', count: 21, percent: 0.21 },
{ item: 'Case 3', count: 17, percent: 0.17 },
{ item: 'Case 4', count: 13, percent: 0.13 },
{ item: 'Case 5', count: 9, percent: 0.09 },
],
coordinate: { type: 'theta', outerRadius: 0.8 },
transform: [{ type: 'stackY' }],
encode: {
y: 'percent',
color: 'item',
},
legend: { color: { position: 'bottom' } },
labels: [
{
text: 'item',
position: 'outside',
fontSize: 12,
},
{
text: (d) => `${(d.percent * 100).toFixed(0)}%`,
position: 'inside',
fontSize: 14,
fontWeight: 'bold',
fill: '#fff',
},
],
interaction: {
elementHoverScale: true,
},
});
chart.render();

Donut Chart Hover Effect

Donut charts also benefit from elementHoverScale interaction:

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
autoFit: true,
});
chart.options({
type: 'interval',
height: 400,
data: [
{ item: 'Case 1', count: 40, percent: 0.4 },
{ item: 'Case 2', count: 21, percent: 0.21 },
{ item: 'Case 3', count: 17, percent: 0.17 },
{ item: 'Case 4', count: 13, percent: 0.13 },
{ item: 'Case 5', count: 9, percent: 0.09 },
],
coordinate: { type: 'theta', innerRadius: 0.5, outerRadius: 0.8 },
transform: [{ type: 'stackY' }],
encode: {
y: 'percent',
color: 'item',
},
legend: { color: { position: 'bottom' } },
labels: [
{
text: 'item',
position: 'spider',
fontSize: 12,
},
],
interaction: {
elementHoverScale: {
scale: 1.08,
shadow: true,
shadowColor: 'rgba(0, 0, 0, 0.5)',
shadowBlur: 15,
},
},
});
chart.render();

Bar Chart Hover Effect

elementHoverScale can also be used in bar charts to highlight individual bars:

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
autoFit: true,
});
chart.options({
type: 'interval',
height: 300,
data: {
type: 'fetch',
value: 'https://gw.alipayobjects.com/os/bmw-prod/fb9db6b7-23a5-4c23-bbef-c54a55fee580.csv',
},
encode: { x: 'letter', y: 'frequency' },
transform: [{ type: 'sortX', by: 'y', reverse: true, slice: 6 }],
axis: { y: { labelFormatter: '.0%' } },
interaction: {
elementHoverScale: {
scale: 1.05,
shadow: true,
},
},
});
chart.render();

Custom Scale Configuration

Fully customize the hover effect through configuration:

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
autoFit: true,
});
chart.options({
type: 'interval',
height: 400,
data: [
{ category: 'A', value: 27 },
{ category: 'B', value: 25 },
{ category: 'C', value: 18 },
{ category: 'D', value: 15 },
{ category: 'E', value: 10 },
{ category: 'F', value: 5 },
],
coordinate: { type: 'theta', outerRadius: 0.75 },
transform: [{ type: 'stackY' }],
encode: { y: 'value', color: 'category' },
legend: { color: { position: 'right' } },
style: {
stroke: '#fff',
lineWidth: 2,
},
interaction: {
elementHoverScale: {
scale: 1.15, // larger scale factor
shadow: true,
shadowColor: 'rgba(139, 0, 139, 0.6)', // custom shadow color
shadowBlur: 20, // larger blur radius
shadowOffsetX: 5, // horizontal offset
shadowOffsetY: 5, // vertical offset
zIndex: 20, // higher z-index
delay: 100, // 100ms delay before reset
},
},
});
chart.render();

Grouped Hover Effect

Use createGroup to achieve linked hover effects across multiple elements:

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
autoFit: true,
});
const data = [
{ year: '2018', type: 'A', value: 100 },
{ year: '2018', type: 'B', value: 80 },
{ year: '2019', type: 'A', value: 120 },
{ year: '2019', type: 'B', value: 90 },
{ year: '2020', type: 'A', value: 140 },
{ year: '2020', type: 'B', value: 110 },
{ year: '2021', type: 'A', value: 160 },
{ year: '2021', type: 'B', value: 130 },
];
chart.options({
type: 'interval',
height: 300,
data,
encode: {
x: 'year',
y: 'value',
color: 'type',
},
transform: [{ type: 'dodgeX' }],
interaction: {
elementHoverScale: {
scale: 1.08,
// group by type, bars of the same type scale together on hover
createGroup: (view) => (d) => d.type,
},
},
});
chart.render();