selectX
Previous
select
Next
selectY
Loading...
selectX
filters data based on the x channel, selecting a subset of data that meets the specified range or condition.
Peak annotation: Mark the highest/lowest points in line charts
Start/end annotation: Highlight start/end points in time series
Category annotation: Differentiate marks for different data categories
Trend annotation: Mark statistical feature points like mean, median, etc.
Property | Description | Type | Default |
---|---|---|---|
groupBy | Group by specified channels | string | string[] | series |
selector | Specify data extraction operation for each group | Selector | first |
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
As shown below, annotate different data types:
import { Chart } from '@antv/g2';const chart = new Chart({container: 'container',});chart.options({width: 800,paddingLeft: 50,paddingRight: 100,data: {type: 'fetch',value: 'https://assets.antv.antgroup.com/g2/indices.json',},children: [// Line mark configuration{type: 'line',encode: {x: (d) => new Date(d.Date),y: 'Close',color: 'Symbol',},axis: {y: {title: '↑ Change in price (%)',},},},// Text annotation configuration{type: 'text',encode: {x: (d) => new Date(d.Date),y: 'Close',series: 'Symbol',color: 'Symbol',text: 'Symbol',},transform: [{// Use selectX transformtype: 'selectX',// Select the last data pointselector: 'last',},],style: {// Offset annotation text 12 pixels to the rightdx: 12,},// Disable tooltip for texttooltip: false,},],});chart.render();