logo

G2

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

beeswarm

Previous
sunburst
Next
point

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...

The beeswarm mark is mainly used to draw beeswarm plots, also known as dot swarm plots. It is a type of statistical visualization chart based on a Cartesian coordinate system. Its core feature is to distribute discrete data points on the coordinate axes in an orderly pattern similar to a "swarm of bees gathering". This approach not only preserves the original information of each individual data point but also clearly presents the local density, dispersion degree, and distribution details of the data by avoiding overlapping between points. It is particularly suitable for analyzing the univariate or bivariate distribution of small to medium-sized datasets.

Getting Started

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
const data = Array.from({ length: 200 }, (_, i) => {
return {
x: `G${(i % 6) + 1}`,
y: 40 + Math.random() * 220,
};
});
chart.options({
type: 'beeswarm',
data,
encode: {
x: 'x',
y: 'y',
size: 4,
},
scale: {
y: {
nice: true,
domainMin: 0,
},
},
legend: {
size: false,
},
axis: {
x: { title: false },
y: { title: false },
},
});
chart.render();

For more examples, check out the Chart Examples - Seeswarm Plot page.

Configuration

PropertyDescriptionTypeDefaultRequired
encodeConfigure visual channels for the beeswarm mark, including x, y, color, shape, size, etc., to specify the relationship between visual element properties and dataencode-✓
styleConfigure graphic style for the beeswarm markstyle-

encode

Configure visual channels for the beeswarm mark.

PropertyDescriptionTypeDefaultRequired
xBind the x property channel for the beeswarm mark, can be numeric fields, ordered nominal, or unordered nominal in dataencode-✓
yBind the y property channel for the beeswarm mark, generally numeric fields in data, used to draw one-dimensional scatter plots when emptyencode-
colorBind the color property channel for the beeswarm mark, generally used to distinguish different data types, mapped to categorical fieldsencode-
shapeBind the shape property channel for the beeswarm mark, changes the drawing shape of the graphic markhollow | hollowDiamond | hollowHexagon | hollowSquare | hollowTriangleDown | hollowTriangle | hollowBowtie | point | plus | diamond | square | triangle | triangleDown | hexagon | cross | bowtie | hyphen | line | tick | circlehollow
sizeBind the size property channel for the beeswarm mark, data field size maps to graphic radius (or 1/2 side length for squares)encode-

x & y

The position visual channels for the beeswarm mark require values from both x and y fields, configuration:

{
type: "beeswarm",
data: [{ month: '一月', temperature: 8 },{ month: '一月', temperature: 18 }],
encode: { x: "month", y: "temperature" },
}

color

The beeswarm visual channel affects the fill color of the beeswarm mark (when applying certain hollow shapes, such as hollow, it changes the stroke color of the graphic). When applied to beeswarm plots, it's generally mapped to categorical fields to group data.

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
const data = Array.from({ length: 300 }, (_, i) => {
return {
x: `G${(i % 6) + 1}`,
y: 40 + Math.random() * 220,
};
});
chart.options({
type: 'beeswarm',
data,
encode: {
x: 'x',
y: 'y',
size: 4,
color: 'x',
},
scale: {
y: {
nice: true,
domainMin: 0,
},
},
legend: {
size: false,
},
axis: {
x: { title: false },
y: { title: false },
},
});
chart.render();

shape

The built-in shape graphics for beeswarm marks are as follows, with hollow as the default.

ShapeDescription
hollowHollow circle
hollowDiamondHollow diamond
hollowHexagonHollow hexagon
hollowSquareHollow square
hollowTriangleDownHollow inverted triangle
hollowTriangleHollow triangle
hollowBowtieHollow bowtie
pointSolid circle
plusPlus symbol
diamondSolid diamond
squareSolid square
triangleSolid triangle
triangleDownSolid inverted triangle
hexagonSolid hexagon
crossCross symbol
bowtieSolid bowtie
hyphenHyphen (short dash)
lineVertical line symbol
tickShort vertical line (tick symbol)
circleCircle symbol

Try it out:

const { Chart } = G2;
const chart = new Chart({
container: 'container',
});
const container = chart.getContainer();
// 可选的itemMarker形状
const shapeList = [
'hollow',
'hollowDiamond',
'hollowHexagon',
'hollowSquare',
'hollowTriangleDown',
'hollowTriangle',
'hollowBowtie',
'point',
'plus',
'diamond',
'square',
'triangle',
'triangleDown',
'hexagon',
'cross',
'bowtie',
'hyphen',
'line',
'tick',
'circle',
];
const shapeMap = shapeList.map((p) => {
return {
label: p,
value: p,
};
});
const data = Array.from({ length: 300 }, (_, i) => {
return {
x: `G${(i % 6) + 1}`,
y: 40 + Math.random() * 220,
radius: Math.random(),
};
});
chart.options({
type: 'beeswarm',
data,
encode: {
x: 'x',
y: 'y',
color: 'x',
shape: 'hollow'
},
scale: {
y: {
nice: true,
domainMin: 0,
},
size: { range: [3, 6] },
},
legend: {
size: false,
},
axis: {
x: { title: false },
y: { title: false },
},
});
const handleSetShape = (shape) => {
chart.options({
encode: {
x: 'x',
y: 'y',
size: 10,
shape,
},
});
chart.render(); // 重新渲染图表
};
const selectorContainer = document.createElement('div');
selectorContainer.textContent = '选择beeswarm标记的形状 ';
const selector = document.createElement('select');
selector.innerHTML = shapeMap.map(
(shape, index) =>
`<option value="${shape.value}" ${index === 0 ? 'selected' : ''}>${
shape.label
}</option>`,
);
selector.onchange = (e) => {
handleSetShape(e.target.value);
};
selectorContainer.appendChild(selector);
container.insertBefore(selectorContainer, container.childNodes[0]);
chart.render();

size

Binding the beeswarm property channel for the beeswarm mark creates a bubble chart, where the size of data fields maps to the radius of the graphic (or 1/2 side length for squares).

import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
});
const data = Array.from({ length: 300 }, (_, i) => {
return {
x: `G${(i % 6) + 1}`,
y: 40 + Math.random() * 220,
radius: Math.random(),
};
});
chart.options({
type: 'beeswarm',
data,
encode: {
x: 'x',
y: 'y',
size: 'radius',
color: 'x',
shape: 'hyphen'
},
scale: {
y: {
nice: true,
domainMin: 0,
},
size: { range: [3, 6] },
},
legend: {
size: false,
},
axis: {
x: { title: false },
y: { title: false },
},
});
chart.render();

style

PropertyDescriptionTypeDefaultRequired
fillbeeswarm mark fill colorstring | (datum, index, data) => string-
fillOpacitybeeswarm mark fill opacitynumber | (datum, index, data) => numberbeeswarm: 0.95
strokebeeswarm mark stroke colorstring | (datum, index, data) => string-
strokeOpacitybeeswarm mark stroke opacitynumber | (datum, index, data) => numberhollow, plus, diamond : 0.95
lineWidthbeeswarm mark stroke widthnumber | (datum, index, data) => numberhollow, diamond: 1
beeswarm: 0
plus: 3
lineDashbeeswarm mark stroke dash configuration[number,number] | (datum, index, data) => [number , number]-
opacitybeeswarm mark overall opacitynumber | (datum, index, data) => number-
shadowColorbeeswarm mark shadow colorstring | (datum, index, data) => string-
shadowBlurbeeswarm mark shadow blur factornumber | (datum, index, data) => number-
shadowOffsetXbeeswarm mark shadow horizontal offsetnumber | (datum, index, data) => number-
shadowOffsetYbeeswarm mark shadow vertical offsetnumber | (datum, index, data) => number-
cursorbeeswarm mark mouse cursor stylestring | (datum, index, data) => stringdefault

Try it out:

import { Chart } from '@antv/g2';
const chart = new Chart({ container: 'container' });
const data = Array.from({ length: 300 }, (_, i) => {
return {
x: `G${(i % 6) + 1}`,
y: 40 + Math.random() * 220,
radius: Math.random(),
};
});
chart.options({
type: 'beeswarm',
style: {
fill: 'skyblue', // 图形填充颜色,支持颜色字符串,优先级高于color通道
fillOpacity: 0.9, // 填充颜色透明度,范围 0-1
stroke: '#FADC7C', // 图形描边颜色
lineWidth: 3, // 描边宽度(像素)
lineDash: [1, 2], // 虚线配置[实线长度, 间隔长度],[0,0]表示无描边
strokeOpacity: 0.95, // 描边透明度,范围 0-1
opacity: 0.9, // 整体透明度,影响填充和描边
shadowColor: 'black', // 阴影颜色
shadowBlur: 10, // 阴影模糊程度(像素)
shadowOffsetX: 5, // 阴影水平偏移量(像素)
shadowOffsetY: 5, // 阴影垂直偏移量(像素)
cursor: 'pointer', // 鼠标悬停样式(同CSS cursor属性)
},
data,
encode: {
x: 'x',
y: 'y',
size: 'radius',
color: 'x',
shape: 'point'
},
scale: {
y: {
nice: true,
domainMin: 0,
},
size: { range: [3, 6] },
},
legend: {
size: false,
},
axis: {
x: { title: false },
y: { title: false },
},
});
chart.render();