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)

Scrollbar

Previous
Legend
Next
Slider

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

In G2, Scrollbar can be used to filter data and can be bound to the x or y channel. Scrollbars are turned off by default. It solves the problem of chart information being too dense to be fully displayed.

When to use: Whether content exceeds the display area depends on the amount of content and the size of the display area. When the content to be displayed exceeds the size of the display area in the vertical direction, a vertical scrollbar should be used to control the displayed portion. The same principle applies to horizontal scrollbars.

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'interval',
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 },
scale: { y: { type: 'log' } },
scrollbar: {
x: {
ratio: 0.2,
trackSize: 14,
trackFill: '#000',
trackFillOpacity: 1,
},
y: {
ratio: 0.5,
trackSize: 12,
value: 0.1,
trackFill: '#000',
trackFillOpacity: 1,
},
},
});
chart.render();

Components

legend-overview

Usage

Scrollbars can be configured at the Mark level. In G2, each Mark has its own scrollbar. If the scales corresponding to marks are synchronized, the scrollbars will also be merged.

({
type: 'interval',
scrollbar: {
x: {}, // x-axis scrollbar
y: {}, // y-axis scrollbar
},
});

Scrollbars can also be configured at the View level. Scrollbars have inheritance properties. Scrollbars declared on a view will be passed to marks declared in children. If the mark has a scrollbar for the corresponding channel, they will be merged; otherwise, it won't affect anything.

({
type: 'view',
scrollbar: {
x: {},
y: {},
},
});

Configuration Options

PropertyDescriptionTypeDefault ValueRequired
ratioScrollbar ratio, the proportion of single page data in total datanumber0.5
valueStarting position of scrollbar, default is 0 for horizontal, 1 for vertical[0, 1]
slidableWhether it can be draggedbooleantrue
scrollableWhether it supports mouse wheel scrollingbooleantrue
positionScrollbar position relative to chartstringbottom
isRoundWhether scrollbar style is roundedbooleantrue
styleScrollbar style configuration, all styles can be configured directlystyle

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'area',
autoFit: true,
height: 300,
data: {
type: 'fetch',
value: 'https://assets.antv.antgroup.com/g2/unemployment-by-industry.json',
},
encode: {
x: (d) => new Date(d.date),
y: 'unemployed',
color: 'industry',
shape: 'smooth',
},
transform: [{ type: 'stackY' }],
scrollbar: {
x: {
// Configuration options
ratio: 0.2,
value: 0.1,
scrollable: true,
slidable: true,
isRound: true,
position: 'top',
// Scrollbar thumb style
thumbFillOpacity: 0.2,
thumbFill: '#000',
thumbStroke: '#000',
// Scrollbar track style
trackFill: '#fa0',
trackStroke: '#f00',
trackLineWidth: 2,
trackFillOpacity: 1,
trackSize: 14,
trackLength: 300,
},
},
});
chart.render();

style

style scrollbar style configuration. Internal processing allows you to configure styles directly in the configuration options. For specific style configurations, refer to Scrollbar Thumb and Scrollbar Track.

Scrollbar Thumb

PropertyDescriptionTypeDefault ValueRequired
thumbFillScrollbar thumb fill colorstring#000
thumbFillOpacityScrollbar thumb fill opacitynumber0.15
thumbStrokeScrollbar thumb stroke colorstring–
thumbLineWidthScrollbar thumb stroke widthnumber–
thumbStrokeOpacityScrollbar thumb stroke opacitynumber–
thumbLineDashScrollbar thumb dash configuration[number,number]–
thumbOpacityScrollbar thumb overall opacitynumber–
thumbShadowColorScrollbar thumb shadow colorstring–
thumbShadowBlurScrollbar thumb shadow blur coefficientnumber–
thumbShadowOffsetXScrollbar thumb shadow horizontal offsetnumber–
thumbShadowOffsetYScrollbar thumb shadow vertical offsetnumber–
thumbCursorScrollbar thumb cursor stylestringdefault
({
scrollbar: {
x: {
thumbFill: '#1173a1',
thumbFillOpacity: 1,
thumbStroke: 'red',
thumbLineWidth: 2,
thumbStrokeOpacity: 0.9,
},
y: {},
},
});

Scrollbar Track

PropertyDescriptionTypeDefault ValueRequired
trackSizeScrollbar track widthnumber10
trackLengthScrollbar track lengthnumber–
trackFillScrollbar track fill colorstring–
trackFillOpacityScrollbar track fill opacitynumber0
trackStrokeScrollbar track stroke colorstring–
trackLineWidthScrollbar track stroke widthnumber–
trackStrokeOpacityScrollbar track stroke opacitynumber–
trackLineDashScrollbar track dash configuration[number,number]–
trackOpacityScrollbar track overall opacitynumber–
trackShadowColorScrollbar track shadow colorstring–
trackShadowBlurScrollbar track shadow blur coefficientnumber–
trackShadowOffsetXScrollbar track shadow horizontal offsetnumber–
trackShadowOffsetYScrollbar track shadow vertical offsetnumber–
trackCursorScrollbar track cursor stylestringdefault
({
scrollbar: {
x: {
trackSize: 20,
trackLength: 300,
trackFillOpacity: 1,
trackFill: 'red',
trackLineWidth: 2,
trackStroke: 'red',
trackStrokeOpacity: 0.4,
},
y: {},
},
});

Events

PropertyDescriptionType
valuechangeTriggered when scroll value changes, listen via event({detail: { oldValue: any; value: any }}) => void

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'interval',
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 },
scale: { y: { type: 'log' } },
scrollbar: { x: true },
});
// After rendering the chart
chart.on('afterrender', () => {
const { canvas } = chart.getContext();
const { document } = canvas;
document
.querySelector('.g2-scrollbar')
.addEventListener('valuechange', (evt) => {
console.log(evt.detail.oldValue); // Data before scroll update
console.log(evt.detail.value); // Data after update
});
});
chart.render();