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)

brushYHighlight

Previous
brushXHighlight
Next
brushFilter

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

brushYHighlight is a specialized brushHighlight interaction. While retaining the basic highlight functionality, it fixes the x-axis brush range to the full domain (from minimum to maximum values), focusing specifically on data selection operations in the y-axis direction. This is suitable for vertical comparison analysis (such as comparing yields of financial products, studying vertical distribution of experimental data), improving operation precision by eliminating horizontal 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: { brushYHighlight: true },
});
chart.render();

Usage

There are two ways to configure the brushYHighlight interaction:

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

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

Second, pass configuration options to configure the interaction.

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

Configuration Level

Interaction can be configured at the Mark level:

({
type: 'interval',
interaction: { brushYHighlight: 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: { brushYHighlight: true },
});

Configuration Options

PropertyDescriptionTypeDefaultRequired
reverseWhether to reverse brushbooleanfalse
seriesWhether for series elementsbooleanfalse
facetWhether across facetsbooleanfalse
selectedHandlesResizable handle directionsstring[]['handle-n', 'handle-s']
brushRegionBrush area(x, y, x1, y1, extent) => any(x, y, x1, y1,[minX, minY, maxX, maxY]) => [minX, y, maxX, y1]
maskStyle of brush area maskmaskSee mask
maskHandleStyle of brush area handlesmaskHandleSee 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 lineDash 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 the mask style of the brush area, it's not configured as an object, but using the mask prefix with property names.

({
interaction: {
brushYHighlight: {
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 (based on cardinal directions). Set corresponding properties using the format mask[handleName][styleAttribute], or use maskHandleSize to set width.

custom-style
PropertyDescriptionTypeDefaultRequired
mask[handleName]RenderCustom render function for mask handle(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 lineDash 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 update size and position is completed
  • 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