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)

brushXHighlight

Previous
brushHighlight
Next
brushYHighlight

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

brushXHighlight is a specialized brushHighlight interaction. While retaining the basic highlight functionality, it fixes the y-axis brush range to the full domain (from minimum to maximum values), focusing specifically on data selection operations in the x-axis direction. This is suitable for scenarios requiring horizontal data comparison (such as time series analysis), improving operation precision by eliminating vertical direction interference.

  • Trigger: Brush selection of elements.

  • End: Click on chart area.

  • Affected states:

Elements within the brush range change to active state.

Elements outside the brush range change to inactive state.

Built-in interaction states:

({
inactive: { opacity: 0.5 },
});
example
import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'point',
autoFit: true,
data: {
type: 'fetch',
value:
'https://gw.alipayobjects.com/os/basement_prod/6b4aa721-b039-49b9-99d8-540b3f87d339.json',
},
encode: { x: 'height', y: 'weight', color: 'gender' },
state: { inactive: { stroke: 'gray' } },
interaction: { brushXHighlight: true },
});
chart.render();

Usage

There are two ways to configure the brushXHighlight interaction:

First, pass a boolean to set whether to enable the interaction.

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

Second, pass configuration options to configure the interaction.

({
type: 'line',
interaction: {
brushXHighlight: {
series: true,
},
},
});

Configuration Level

Interaction can be configured at the Mark level:

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

It can also be configured at the View level. Interactions declared on the view will be passed to marks declared in children. If the mark has declared the corresponding interaction, they will be merged; otherwise, it won't be affected.

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

Configuration Options

PropertyDescriptionTypeDefaultRequired
reverseWhether to reverse the brushbooleanfalse
seriesWhether brush affects series elementsbooleanfalse
facetWhether brush spans across facetsbooleanfalse
selectedHandlesDirections of handles that can be resizedstring[]['handle-e', 'handle-w']
brushRegionBrush region(x, y, x1, y1, extent) => any(x, y, x1, y1,[minX, minY, maxX, maxY]) => [x, minY, x1, maxY]
maskMask style for brush areamaskSee mask
maskHandleHandle style for brush areamaskHandleSee maskHandle

mask

Configure the style of the brush area mask.

PropertyDescriptionTypeDefaultRequired
maskFillMask fill colorstring#777
maskFillOpacityMask fill opacitynumber0.3
maskStrokeMask strokestring#fff
maskStrokeOpacityStroke opacitynumber
maskLineWidthMask stroke widthnumber
maskLineDashStroke dash configuration. First value is dash length, second is gap length. Setting to [0,0] means no stroke.[number,number]
maskOpacityMask overall opacitynumber
maskShadowColorMask shadow colorstring
maskShadowBlurMask shadow Gaussian blur coefficientnumber
maskShadowOffsetXSet horizontal distance of shadow from masknumber
maskShadowOffsetYSet vertical distance of shadow from masknumber
maskCursorMouse cursor style. Same as CSS cursor stylestringdefault

When configuring brush area mask style, it's not configured as an object, but using the mask prefix with property names.

({
interaction: {
brushXHighlight: {
maskFill: '#000',
maskFillOpacity: 0.2,
maskStroke: 'red',
maskStrokeOpacity: 0.9,
maskLineWidth: 2,
maskLineDash: [4, 8],
maskOpacity: 0.2,
maskShadowColor: '#d3d3d3',
maskShadowBlur: 10,
maskShadowOffsetX: 10,
maskShadowOffsetY: 10,
maskCursor: 'pointer',
},
},
});

maskHandle

The names of handles in eight directions are as follows (named according to north, south, east, west). Set corresponding properties in the format mask[handleName][styleAttribute], or set width through maskHandleSize.

custom-style
PropertyDescriptionTypeDefaultRequired
mask[handleName]RenderCustom mask handle rendering function(g, options, document) => DisplayObject
mask[handleName]SizeMask handle widthstring
mask[handleName]FillMask handle fill colorstring
mask[handleName]FillOpacityMask handle fill opacitynumber
mask[handleName]StrokeMask handle strokestring
mask[handleName]StrokeOpacityStroke opacitynumber
mask[handleName]LineWidthMask handle stroke widthnumber
mask[handleName]LineDashStroke dash configuration. First value is dash length, second is gap length. Setting to [0,0] means no stroke.[number,number]
mask[handleName]OpacityMask handle overall opacitynumber
mask[handleName]ShadowColorMask handle shadow colorstring
mask[handleName]ShadowBlurMask handle shadow Gaussian blur coefficientnumber
mask[handleName]ShadowOffsetXSet horizontal distance of shadow from mask handlenumber
mask[handleName]ShadowOffsetYSet vertical distance of shadow from mask handlenumber
mask[handleName]CursorMouse cursor style. Same as CSS cursor stylestringdefault

Events

Listening to Events

The following events are supported:

  • brush:start - Triggered when starting to create brush
  • brush:end - Triggered when brush size and position update is complete
  • brush:remove - Triggered when brush is removed
  • brush:highlight - Triggered when brush changes size and position
chart.on('brush:highlight', (e) => {
console.log(e.data.selection);
console.log(e.nativeEvent);
});

Triggering Interaction

The following events are supported:

  • brush:highlight - Highlight data
  • brush:remove - Remove brush
chart.emit('brush:remove');
chart.emit('brush:highlight', { data: { selection } });

Examples

Multi-view Chart Linkage

(() => {
const container = document.createElement('div');
const focusContainer = document.createElement('div');
const contextContainer = document.createElement('div');
container.append(focusContainer);
container.append(contextContainer);
function createPathRender(compute) {
return (group, options, document) => {
if (!group.handle) {
const path = document.createElement('path');
group.handle = path;
group.appendChild(group.handle);
}
const { handle } = group;
const { x, y, width, height, ...rest } = options;
if (width === undefined || height === undefined) return handle;
handle.attr({ ...compute(x, y, width, height), ...rest });
return handle;
};
}
// Render focus view
const focus = new G2.Chart({
container: focusContainer,
height: 360,
paddingLeft: 50,
});
focus
.area()
.data({
type: 'fetch',
value:
'https://gw.alipayobjects.com/os/bmw-prod/551d80c6-a6be-4f3c-a82a-abd739e12977.csv',
})
.encode('x', 'date')
.encode('y', 'close')
.animate(false)
.interaction('brushXHighlight', {
series: true,
maskHandleWRender: createPathRender((x, y, w, h) => ({
d: `M${x + w / 2},${y}L${x - w / 2},${y + h / 2}L${x + w / 2},${y + h}Z`,
fill: '#1890FF',
})),
maskHandleERender: createPathRender((x, y, w, h) => ({
d: `M${x + w / 2},${y}L${x + (w * 3) / 2},${y + h / 2}L${x + w / 2},${y + h}Z`,
fill: '#1890FF',
})),
});
// Render context view
const context = new G2.Chart({
container: contextContainer,
height: 80,
paddingLeft: 50,
});
context
.area()
.data({
type: 'fetch',
value:
'https://gw.alipayobjects.com/os/bmw-prod/551d80c6-a6be-4f3c-a82a-abd739e12977.csv',
})
.encode('x', 'date')
.encode('y', 'close')
.animate(false)
.axis('x', { title: false })
.axis('y', false)
.interaction('brushXHighlight', {
series: true,
maskHandleWRender: createPathRender((x, y, w, h) => ({
d: `M${x + w / 2},${y}L${x - w / 2},${y + h / 2}L${x + w / 2},${y + h}Z`,
fill: '#1890FF',
})),
maskHandleERender: createPathRender((x, y, w, h) => ({
d: `M${x + w / 2},${y}L${x + (w * 3) / 2},${y + h / 2}L${x + w / 2},${y + h}Z`,
fill: '#1890FF',
})),
});
Promise.all([focus.render(), context.render()]).then(() => {
// Add cross-chart linkage
context.on('brush:highlight', (e) => {
const { selection } = e.data;
focus.emit('brush:highlight', { data: { selection } });
});
focus.on('brush:highlight', (e) => {
const { selection } = e.data;
context.emit('brush:highlight', { data: { selection } });
});
});
return container;
})();