logo

G2

  • Chart Gallery
  • Docs
  • Examples
  • Theme
  • Ecosystem
  • Productsantv logo arrow
  • 5.3.5
  • 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
      • 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)

boxplot

Previous
box
Next
cell

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 boxplot mark is used to draw boxplots (also known as box-and-whisker plots), which are statistical charts used to display the distribution of a dataset. Boxplots typically contain the following key statistical values:

  • Minimum: The smallest value in the dataset (excluding outliers)
  • Lower Quartile (Q1): The value at the 25th percentile of the dataset
  • Median (Q2): The value at the 50th percentile of the dataset
  • Upper Quartile (Q3): The value at the 75th percentile of the dataset
  • Maximum: The largest value in the dataset (excluding outliers)
  • Outliers: Data points that fall outside the normal range

Both boxplot and box marks can be used to draw boxplots, but they have the following differences:

  • boxplot is a high-level mark with built-in data grouping and statistical aggregation functionality
  • box is an atomic mark that requires developers to manually specify data for the 5 points

Therefore, boxplot is more suitable for frontend data exploration and analysis, while box is more suitable for visualization after backend computation and statistics on large datasets.

boxplot

Configuration

PropertyDescriptionTypeDefault ValueRequired
encodeConfigure visual channels for the boxplot mark, including x, y, color, shape, etc.encode-✓
styleConfigure the graphic style of the boxplot markstyle-
pointWhether to show outliersbooleantrue

encode

Configure visual channels for the boxplot mark.

PropertyDescriptionTypeDefault ValueRequired
xBind the x property channel for the boxplot mark, usually a categorical fieldencode-✓
yBind the y property channel for the boxplot mark, usually a numeric field used to calculate boxplot statistical valuesencode-✓
colorBind the color property channel for the boxplot mark, used to distinguish boxplots of different categoriesencode-
shapeBind the shape property channel for the boxplot mark, available values are box, violin'box' | 'violin''box'
seriesBind the series property channel for the boxplot mark, used for grouped display of boxplotsencode-

style

Configure the graphic style of the boxplot mark. The boxplot consists of two parts: the box and the outlier points. Therefore, style configuration is also divided into two parts, prefixed with box and point respectively.

Box Style

PropertyDescriptionTypeDefault ValueRequired
boxFillFill color of the boxstring | (datum, index, data, column) => string-
boxFillOpacityFill opacity of the boxnumber | (datum, index, data, column) => number0.95
boxStrokeStroke color of the boxstring | (datum, index, data, column) => string#000
boxLineWidthWidth of the box strokenumber | (datum, index, data, column) => number1
boxLineDashDash pattern for box stroke, first value is length of each dash segment, second is gap between dashes[number,number] | (datum, index, data, column) => [number, number]-
boxLineOpacityOpacity of the box strokenumber | (datum, index, data, column) => number-
boxOpacityOverall opacity of the boxnumber | (datum, index, data, column) => number-
boxShadowColorShadow color of the boxstring | (datum, index, data, column) => string-
boxShadowBlurGaussian blur coefficient for the box shadownumber | (datum, index, data, column) => number-
boxShadowOffsetXHorizontal distance of shadow from boxnumber | (datum, index, data, column) => number-
boxShadowOffsetYVertical distance of shadow from boxnumber | (datum, index, data, column) => number-
boxCursorMouse cursor style. Same as CSS cursor stylestring | (datum, index, data, column) => string'default'

Outlier Point Style

PropertyDescriptionTypeDefault ValueRequired
pointFillFill color of outlier pointsstring | (datum, index, data, column) => string-
pointFillOpacityFill opacity of outlier pointsnumber | (datum, index, data, column) => number-
pointStrokeStroke color of outlier pointsstring | (datum, index, data, column) => string-
pointLineWidthWidth of outlier point strokenumber | (datum, index, data, column) => number-
pointLineDashDash pattern for outlier point stroke[number,number] | (datum, index, data, column) => [number, number]-
pointStrokeOpacityStroke opacity of outlier pointsnumber | (datum, index, data, column) => number-
pointOpacityOverall opacity of outlier pointsnumber | (datum, index, data, column) => number-
pointShadowColorShadow color of outlier pointsstring | (datum, index, data, column) => string-
pointShadowBlurGaussian blur coefficient for point shadownumber | (datum, index, data, column) => number-
pointShadowOffsetXHorizontal distance of shadow from pointnumber | (datum, index, data, column) => number-
pointShadowOffsetYVertical distance of shadow from pointnumber | (datum, index, data, column) => number-
pointCursorMouse cursor style. Same as CSS cursor stylestring | (datum, index, data, column) => string'default'

Examples

Basic Boxplot

Use the boxplot mark to quickly create a boxplot with automatic calculation of statistical values.

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'boxplot',
data: {
type: 'fetch',
value: 'https://assets.antv.antgroup.com/g2/morley.json',
},
encode: {
x: 'Expt',
y: 'Speed',
},
style: {
boxFill: '#aaa',
pointStroke: '#000',
},
});
chart.render();

Boxplot Without Outliers

Set point: false to hide outliers and show only the box portion.

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'boxplot',
data: {
type: 'fetch',
value: 'https://assets.antv.antgroup.com/g2/morley.json',
},
encode: {
x: 'Expt',
y: 'Speed',
},
style: {
point: false,
},
});
chart.render();

Grouped Boxplot

Use the color and series channels to create grouped boxplots.

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'boxplot',
data: {
type: 'fetch',
value: 'https://assets.antv.antgroup.com/g2/penguins.json',
},
encode: {
x: 'species',
y: 'flipper_length_mm',
color: 'sex',
series: 'sex',
},
});
chart.render();

Horizontal Boxplot

Create a horizontal boxplot by transposing the coordinate system.

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'boxplot',
coordinate: { transform: [{ type: 'transpose' }] },
data: {
type: 'fetch',
value: 'https://assets.antv.antgroup.com/g2/morley.json',
transform: [{ type: 'filter', callback: (d) => d.Expt === 1 }],
},
encode: {
y: 'Speed',
},
style: {
boxFill: '#aaa',
pointStroke: '#000',
},
});
chart.render();

Violin Plot

Create a violin-shaped boxplot by setting shape: 'violin'.

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'boxplot',
data: {
type: 'fetch',
value: 'https://assets.antv.antgroup.com/g2/penguins.json',
},
encode: {
x: 'species',
y: 'flipper_length_mm',
color: 'species',
shape: 'violin',
},
style: {
opacity: 0.5,
strokeOpacity: 0.5,
point: false,
},
});
chart.render();

Adjusting Box Width

You can adjust box width and spacing by setting the scale parameters for the x-axis.

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'boxplot',
data: {
type: 'fetch',
value: 'https://assets.antv.antgroup.com/g2/morley.json',
},
encode: {
x: 'Expt',
y: 'Speed',
},
scale: {
x: {
paddingInner: 0.1, // Smaller spacing, wider boxes
paddingOuter: 0.05,
},
},
style: {
boxFill: '#4e79a7',
boxStroke: '#2f4b7c',
pointFill: '#e15759',
pointStroke: '#c42e32',
},
});
chart.render();

FAQ

How to Set Box Width?

The box width of the boxplot mark is controlled by the band scale of the x-axis. You can adjust the box width by setting the paddingInner, paddingOuter, or padding parameters of scale.x:

  • paddingInner: Controls the spacing between adjacent boxes; larger values make boxes narrower
  • paddingOuter: Controls the spacing at both ends; larger values make the overall layout more compact
  • padding: A shortcut to set both paddingInner and paddingOuter simultaneously

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
// Example of adjusting box width
chart.options({
type: 'boxplot',
data: {
type: 'fetch',
value: 'https://assets.antv.antgroup.com/g2/morley.json',
},
encode: {
x: 'Expt',
y: 'Speed',
},
scale: {
x: {
paddingInner: 0.3, // Box spacing; larger values make boxes narrower
paddingOuter: 0.1, // End spacing
},
// Or use padding to set both at once
// x: { padding: 0.2 }
},
});
chart.render();

For grouped boxplots, you can also control the spacing between boxes within groups through the scale parameters of the series channel:

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
chart.options({
type: 'boxplot',
data: {
type: 'fetch',
value: 'https://assets.antv.antgroup.com/g2/penguins.json',
},
encode: {
x: 'species',
y: 'flipper_length_mm',
color: 'sex',
series: 'sex',
},
scale: {
x: { paddingInner: 0.2, paddingOuter: 0.1 }, // Control inter-group spacing
series: { paddingInner: 0.1, paddingOuter: 0.05 }, // Control intra-group spacing
},
});
chart.render();

How to draw boxplots with large datasets?

When dealing with large datasets, you can compute outliers and quartile points on the server side, then use the box mark to draw boxplots. In this case, using the box mark is more efficient than the boxplot mark because the box mark doesn't require statistical calculations on the frontend.

For detailed usage, please refer to the box mark documentation.