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)

selectY

Previous
selectX
Next
sortColor

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

selectY filters data based on the y channel, selecting a subset of data that meets specific ranges or conditions.

selectY

Use Cases

  • Peak annotation: Mark the highest/lowest points in line charts

  • Start/end annotation: Highlight start/end points in time series

  • Category annotation: Apply differentiated marking for different data categories

  • Trend annotation: Mark statistical features like mean, median values

Configuration

PropertyDescriptionTypeDefault
groupByGroup by specified channelsstring | string[]series
selectorSpecify data extraction operation for each groupSelectorfirst

selector

type Selector =
| 'min' // Minimum value
| 'max' // Maximum value
| 'first' // First value
| 'last' // Last value
| 'mean' // Mean value
| 'median' // Median value
| ((I: number[], V: number[]) => number[]); // Custom selection function

Examples

As shown below, annotate the highest temperature for each city in the chart:

import { Chart } from '@antv/g2';
const data = [
{ month: 1, city: 'Tokyo', temperature: 7 },
{ month: 1, city: 'London', temperature: 3.9 },
{ month: 2, city: 'Tokyo', temperature: 6.9 },
{ month: 2, city: 'London', temperature: 4.2 },
{ month: 3, city: 'Tokyo', temperature: 9.5 },
{ month: 3, city: 'London', temperature: 5.7 },
{ month: 4, city: 'Tokyo', temperature: 14.5 },
{ month: 4, city: 'London', temperature: 8.5 },
{ month: 5, city: 'Tokyo', temperature: 18.4 },
{ month: 5, city: 'London', temperature: 11.9 },
{ month: 6, city: 'Tokyo', temperature: 21.5 },
{ month: 6, city: 'London', temperature: 15.2 },
{ month: 7, city: 'Tokyo', temperature: 25.2 },
{ month: 7, city: 'London', temperature: 17 },
{ month: 8, city: 'Tokyo', temperature: 26.5 },
{ month: 8, city: 'London', temperature: 16.6 },
{ month: 9, city: 'Tokyo', temperature: 23.3 },
{ month: 9, city: 'London', temperature: 14.2 },
{ month: 10, city: 'Tokyo', temperature: 18.3 },
{ month: 10, city: 'London', temperature: 10.3 },
{ month: 11, city: 'Tokyo', temperature: 13.9 },
{ month: 11, city: 'London', temperature: 6.6 },
{ month: 12, city: 'Tokyo', temperature: 9.6 },
{ month: 12, city: 'London', temperature: 4.8 },
];
const chart = new Chart({
container: 'container',
});
chart.options({
width: 800,
paddingLeft: 50,
paddingRight: 100,
data,
children: [
// Line chart mark configuration
{
type: 'line',
encode: {
x: 'month',
y: 'temperature',
color: 'city',
},
axis: {
y: {
title: 'Temperature',
},
},
},
// Text mark configuration
{
type: 'text',
encode: {
x: 'month',
y: 'temperature',
series: 'city',
text: (d) => `Max Temperature: ${d.temperature}°C`,
},
transform: [
{
// Use selectY transform
type: 'selectY',
// Select maximum value
selector: 'max',
},
],
style: {
// Offset annotation text by 12 pixels along y-axis
dy: -12,
},
// Disable tooltip for text mark
tooltip: false,
},
// Point mark configuration
{
type: 'point',
encode: {
x: 'month',
y: 'temperature',
color: 'city',
series: 'city',
},
transform: [
{
// Use selectY transform
type: 'selectY',
// Select maximum value
selector: 'max',
},
],
// Disable tooltip for point mark
tooltip: false,
},
],
});
chart.render();