logo

G2

  • Chart Gallery
  • Docs
  • Examples
  • Theme
  • Ecosystem
  • Productsantv logo arrow
  • 5.4.3
  • Get Started
  • Introduction
    • What is G2
    • Using in Frontend Frameworks
    • Experimental Spec API
  • Chart API
  • Core Concepts
    • G2's complete configuration system
    • Chart
      • Components of G2 Charts
      • Chart Lifecycle
    • Mark
      • Overview
      • area
      • box
      • boxplot
      • cell
      • chord
      • density
      • gauge
      • heatmap
      • image
      • interval
      • line
      • lineX
      • lineY
      • link
      • liquid
      • sunburst
      • beeswarm
      • 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
      • sliderWheel
      • 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)

sliderFilter

Previous
scrollbarFilter
Next
sliderWheel

Resource

Ant Design
Galacea Effects
Umi-React Application Framework
Dumi-Component doc generator
ahooks-React Hooks Library
WeaveFox-AI Coding Assistant

Community

Ant Financial Experience Tech
seeconfSEE Conf-Experience Tech Conference
weavefoxWeaveFox-AI Developer Community

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-Interactive solution
weavefoxWeaveFox-AI Coding Assistant
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

Overview

The sliderFilter interaction targets the data domain, filtering the displayed data range through slider controls. It allows users to dynamically adjust the data range displayed in visualization charts by dragging sliders, thus enabling interactive data filtering.

  • Trigger: Drag slider component
  • End: Release slider
  • Effect: Update chart's displayed data range
example

Usage

There are two ways to configure the sliderFilter interaction: First, automatically enable slider filtering interaction by configuring the slider component:

({
slider: {
x: true,
y: true,
},
});

Second, configure directly in the interaction:

({
slider: {
x: true,
},
interaction: {
sliderFilter: true, // Use default configuration
},
});

Configuration Level

The interaction can be configured at the View level:

({
type: 'view',
slider: { x: true, y: true },
interaction: { sliderFilter: true },
});

Configuration Options

PropertyDescriptionTypeDefaultRequired
initDomainInitialize coordinate axis range{ x: [number, number], y: [number, number] }{}
classNameCSS class name for slider componentstring'slider'
prefixSlider component prefix, used for identification and event namingstring'slider'
setValueCustom function to set slider value(component, values) => void(component, values) => component.setValues(values)
hasStateWhether to save slider ratio statebooleanfalse
waitThrottle wait time (milliseconds)number50
leadingWhether to execute at the beginning during throttlingbooleantrue
trailingWhether to execute at the end during throttlingbooleanfalse
adaptiveModeAdaptive filtering mode'filter' | false | null'filter'
getInitValuesFunction to get initial slider values(slider) => [number, number]undefined

slider Component Configuration

In addition to the configuration for sliderFilter interaction, the slider component itself has some important configuration options that affect the behavior of slider filtering:

PropertyDescriptionTypeDefaultRequired
paddingSlider inner paddingnumber | number[]-
valuesInitial selection range of slider, in 0 ~ 1 interval[number, number]-
slidableWhether to allow dragging selection and handlesbooleantrue

For detailed documentation see Slider Component

Adaptive Filtering Mode

The adaptiveMode configuration option controls the adaptive filtering behavior of the slider:

  • 'filter': Enable adaptive filtering, dynamically adjust other a xi s' domain values based on selected data range (default value)
  • false or null: Disable adaptive filtering

How Adaptive Filtering Works:

  • Single-axis Adaptive: When only X-axis or only Y-axis has a slider configured, dragging the slider will automatically adjust the display range of the other axis based on the currently selected data range
  • Multi-axis Adaptive: When there are independent coordinate axis in the chart, the system will adopt different adaptive strategies based on the configuration level of the slider
  • Bidirectional Mutual Exclusion: If both X-axis and Y-axis have sliders configured, the adaptive function will not take effect
({
slider: {
x: { values: [0.1, 0.8] }
},
interaction: {
sliderFilter: {
adaptiveMode: 'filter' // Enable adaptive filtering (default value)
// adaptiveMode: false // Disable adaptive filtering
}
}
})

Events

Triggering Events

Slider filtering interaction supports the following events:

  • sliderX:filter - Trigger X axis filtering
  • sliderY:filter - Trigger Y axis filtering
chart.emit('sliderX:filter', {
data: { selection: [['2001-01', '2001-03'], undefined] },
});
chart.emit('sliderY:filter', {
data: { selection: [undefined, [50, 550]] },
});

Listening to Data

  • sliderX:filter - X axis slider filter event
  • sliderY:filter - Y axis slider filter event
chart.on('sliderX:filter', (event) => {
const { data, nativeEvent } = event;
if (nativeEvent) console.log('sliderX:filter', data.selection);
});
chart.on('sliderY:filter', (event) => {
const { data, nativeEvent } = event;
if (nativeEvent) console.log('sliderY:filter', data.selection);
});

Examples

Basic Slider Filtering

The following example shows how to add basic X-axis slider filtering functionality to a line chart:

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'line',
autoFit: true,
height: 300,
data: {
type: 'fetch',
value:
'https://gw.alipayobjects.com/os/bmw-prod/fb9db6b7-23a5-4c23-bbef-c54a55fee580.csv',
},
encode: { x: 'letter', y: 'frequency', y1: 0.000001 },
slider: { x: true },
interaction: {
sliderFilter: {
wait: 100,
leading: false,
tariling: true,
},
},
});
chart.render();

Adaptive Filtering Examples

Single-axis Adaptive Filtering

When only X-axis slider is configured, dragging the X-axis slider will automatically adjust the Y-axis display range:

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
autoFit: true,
});
// Generate interesting data with some outliers
const data = [];
for (let i = 0; i < 50; i++) {
const baseValue = Math.sin(i / 8) * 30 + 50;
// Add outliers in specific range
const anomaly = (i >= 20 && i <= 25) ? Math.random() * 150 : 0;
data.push({
time: i,
value: baseValue + anomaly + Math.random() * 10,
category: i % 3 === 0 ? 'A' : i % 3 === 1 ? 'B' : 'C'
});
}
chart.options({
type: 'point',
data,
encode: { x: 'time', y: 'value', color: 'category' },
slider: {
x: {
values: [0.2, 0.8],
labelFormatter: (d) => `Time: ${Math.round(d)}`
}
},
interaction: {
sliderFilter: {
adaptiveMode: 'filter' // Enable adaptive filtering
}
},
style: {
fillOpacity: 0.8
}
});
chart.render();

Y-axis Adaptive Filtering

When only Y-axis slider is configured, dragging the Y-axis slider will automatically adjust the X-axis display range:

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
autoFit: true,
});
chart.options({
type: 'line',
data: {
type: 'fetch',
value: 'https://gw.alipayobjects.com/os/bmw-prod/551d80c6-a6be-4f3c-a82a-abd739e12977.csv'
},
encode: { x: 'date', y: 'close' },
slider: {
y: {
values: [0.1, 0.9],
labelFormatter: (d) => `Price: ${Math.round(d)}`
}
},
interaction: {
sliderFilter: {
adaptiveMode: 'filter' // Enable adaptive filtering
}
}
});
chart.render();

Disable Adaptive Filtering

If adaptive functionality is not needed, you can explicitly disable it:

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
autoFit: true,
});
const data = [];
for (let i = 0; i < 100; i++) {
data.push({
x: i,
y: Math.sin(i / 10) * 50 + 100 + Math.random() * 20
});
}
chart.options({
type: 'line',
data,
encode: { x: 'x', y: 'y' },
slider: {
x: {
values: [0.3, 0.7]
}
},
interaction: {
sliderFilter: {
adaptiveMode: false // Disable adaptive filtering
}
},
scale: {
y: { domain: [0, 200] } // Fixed Y-axis range
}
});
chart.render();