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)

brushAxisHighlight

Previous
Overview
Next
brushHighlight

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

The brushAxisHighlight interaction targets the coordinate axis, allowing users to brush select areas on axis to highlight corresponding chart elements. This interaction is particularly suitable for parallel coordinate charts, helping users quickly filter and analyze multi-dimensional data.

  • Trigger: Brush selection on the coordinate axis.
  • End: Click on non-brush areas of the axis or double-click on an existing brush area.
  • Affected States:
    • Elements within the brush range become active.
    • Elements outside the brush range become inactive.

Built-in interaction states:

({
// Define inactive state element opacity as 0.5
state: { inactive: { opacity: 0.5 } },
});
example

Usage

There are two ways to configure the brushAxisHighlight interaction:

First, pass a boolean to enable or disable the interaction.

({
type: 'line',
interaction: { brushAxisHighlight: true }, // Use default configuration
});

Second, pass configuration options to customize the interaction.

({
type: 'line',
interaction: {
brushAxisHighlight: {
maskFill: 'red',
maskOpacity: 0.8,
},
},
});

Configuration Levels

The interaction can be configured at the Mark level:

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

It can also be configured at the View level, where interactions declared on the view are passed to marks declared in children:

({
type: 'view',
interaction: { brushAxisHighlight: true },
children: [
{
type: 'line',
// Inherits parent interaction configuration
},
],
});

Configuration Options

PropertyDescriptionTypeDefault ValueRequired
reverseWhether to reverse the brush; when reversed, elements outside the selection area will be highlightedbooleanfalse
facetWhether brush spans across facets, controlling interaction behaviorbooleanfalse
selectedHandlesResizable handle directionsstring[]['handle-n','handle-e','handle-s','handle-w','handle-nw','handle-ne','handle-se','handle-sw']
brushRegionCustom brush region, generally not configured, used internally by G2 for brushXHighlight and brushYHighlight(x, y, x1, y1, extent) => any(x, y, x1, y1) => [x, y, x1, y1]
maskStyle of the brush area maskObjectSee mask section below
maskHandleStyle of the brush area handlesObjectSee maskHandle section below

mask

Configure the style of the brush area mask.

PropertyDescriptionTypeDefault ValueRequired
maskFillFill color of the maskstring#777
maskFillOpacityFill opacity of the masknumber0.3
maskStrokeStroke of the maskstring#fff
maskStrokeOpacityStroke opacitynumber
maskLineWidthWidth of the mask strokenumber
maskLineDashDash configuration for stroke, first value is dash length, second is gap distance[number,number]
maskOpacityOverall opacity of the masknumber
maskShadowColorShadow color of the maskstring
maskShadowBlurGaussian blur coefficient for mask shadownumber
maskShadowOffsetXHorizontal distance of shadow from masknumber
maskShadowOffsetYVertical distance of shadow from masknumber
maskCursorMouse cursor style. Same as CSS cursor stylesstringdefault

When configuring the brush area mask style, instead of using an object format, configure with mask prefix plus property:

({
interaction: {
brushAxisHighlight: {
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 eight directional handles are named as follows (using compass directions). Set corresponding properties using the format mask[handleName][styleAttribute], or set width with maskHandleSize.

custom-style

PropertyDescriptionTypeDefault ValueRequired
mask[handleName]RenderCustom render function for mask handles(g, options, document) => DisplayObject
mask[handleName]SizeWidth of mask handlesstring
mask[handleName]FillFill color of mask handlesstring
mask[handleName]FillOpacityFill opacity of mask handlesnumber
mask[handleName]StrokeStroke of mask handlesstring
mask[handleName]StrokeOpacityStroke opacitynumber
mask[handleName]LineWidthWidth of mask handle strokenumber
mask[handleName]LineDashDash configuration for stroke, first value is dash length, second is gap distance[number,number]
mask[handleName]OpacityOverall opacity of mask handlesnumber
mask[handleName]ShadowColorShadow color of mask handlesstring
mask[handleName]ShadowBlurGaussian blur coefficient for mask handle shadownumber
mask[handleName]ShadowOffsetXHorizontal distance of shadow from mask handlenumber
mask[handleName]ShadowOffsetYVertical distance of shadow from mask handlenumber
mask[handleName]CursorMouse cursor style. Same as CSS cursor stylesstringdefault

Events

Listening to Events

The following events are supported:

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

Triggering Interactions

The following events are supported:

  • brushAxis:highlight - Highlight data
  • brushAxis:remove - Remove brush
chart.emit('brushAxis:highlight', {
data: { selection: [[20, 30], undefined, [100, 300]] },
});
chart.emit('brushAxis:remove', {});

Examples

Parallel Coordinate Brush Highlighting

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
const axis = {
zIndex: 1,
titlePosition: 'right',
line: true,
style: {
labelStroke: '#fff',
labelStrokeWidth: 5,
labelFontSize: 10,
labelStrokeLineJoin: 'round',
titleStroke: '#fff',
titleFontSize: 10,
titleStrokeWidth: 5,
titleStrokeLineJoin: 'round',
titleTransform: 'translate(-50%, 0) rotate(-90)',
lineStroke: 'black',
tickStroke: 'black',
lineStrokeWidth: 1,
},
};
chart.options({
type: 'line',
data: {
type: 'fetch',
value: 'https://assets.antv.antgroup.com/g2/cars3.json',
},
coordinate: { type: 'parallel' },
encode: {
position: [
'economy (mpg)',
'cylinders',
'displacement (cc)',
'power (hp)',
'weight (lb)',
'0-60 mph (s)',
'year',
],
color: 'weight (lb)',
},
style: {
lineWidth: 1.5,
strokeOpacity: 0.4,
},
scale: {
color: {
type: 'sequential',
palette: 'brBG',
offset: (t) => 1 - t,
},
},
legend: {
color: {
length: 400,
layout: { justifyContent: 'center' },
},
},
state: {
active: { lineWidth: 5 },
inactive: { stroke: '#eee', opacity: 0.5 },
},
axis: Object.fromEntries(
Array.from({ length: 7 }, (_, i) => [
`position${i === 0 ? '' : i}`,
{
...axis,
title: true,
},
]),
),
interaction: {
brushAxisHighlight: {
maskFill: '#000',
maskFillOpacity: 0.2,
maskStroke: '#1890ff',
maskLineWidth: 1,
},
tooltip: false,
},
});
chart.render();

Custom Handle Styles

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'point',
data: [
{ x: 10, y: 5, category: 'A' },
{ x: 15, y: 8, category: 'A' },
{ x: 20, y: 12, category: 'A' },
{ x: 25, y: 15, category: 'A' },
{ x: 30, y: 10, category: 'B' },
{ x: 35, y: 7, category: 'B' },
{ x: 40, y: 13, category: 'B' },
{ x: 45, y: 18, category: 'B' },
{ x: 50, y: 20, category: 'C' },
{ x: 55, y: 16, category: 'C' },
{ x: 60, y: 9, category: 'C' },
{ x: 65, y: 6, category: 'C' },
],
encode: {
color: 'category',
x: 'x',
y: 'y',
},
state: {
inactive: { stroke: 'gray', opacity: 0.5 },
},
interaction: {
brushAxisHighlight: {
maskHandleSize: 20,
maskHandleNFill: 'blue',
maskHandleEFill: 'red',
maskHandleSFill: 'green',
maskHandleWFill: 'yellow',
maskHandleNWFill: 'black',
maskHandleNEFill: 'steelblue',
maskHandleSEFill: 'pink',
maskHandleSWFill: 'orange',
},
},
});
chart.render();