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)

boxplot

Previous
box
Next
cell

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

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();

FAQ

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.