logo

Ant Design Charts

  • Manual
  • Options
  • Examples
  • Productsantv logo arrow
  • 2.0.0
  • Component Overview
  • Common Configuration Statistical Charts
    • Chart composition
    • Component
      • 标题(Title)
      • Axis
      • Legend
      • Scrollbar
      • Slider
      • Tooltip
      • Label
    • Core
      • Color En
      • View
      • Data
        • overview
        • custom
        • ema
        • fetch
        • filter
        • fold
        • inline
        • join
        • kde
        • log
        • map
        • pick
        • rename
        • slice
        • sort
        • sortBy
      • Scale
        • overview
        • band
        • linear
        • log
        • ordinal
        • point
        • pow
        • quantile
        • quantize
        • sqrt
        • threshold
        • time
      • Transform
        • overview
        • bin
        • binX
        • diffY
        • dodgeX
        • flexX
        • group
        • groupColor
        • groupX
        • groupY
        • jitter
        • jitterX
        • jitterY
        • normalizeY
        • pack
        • sample
        • select
        • selectX
        • selectX
        • sortColor
        • sortX
        • sortY
        • stackEnter
        • stackY
        • symmetryY
      • Coordinate
        • overview
        • fisheye
        • parallel
        • polar
        • radial
        • theta
        • transpose
        • cartesian3D
      • 样式(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
        • fisheye
        • legendFilter
        • legendHighlight
        • poptip
        • scrollbarFilter
        • sliderFilter
      • Composition
        • overview
        • facetCircle
        • facetRect
        • repeatMatrix
        • spaceFlex
        • spaceLayer
        • timingKeyframe
      • Theme
        • overview
        • Academy
        • classic
        • classicDark
      • event
    • Specal Plot
      • Area
      • Bar
      • CirclePacking
      • DualAxes
      • Gauge
      • Line
      • Rose
      • Sankey
      • Scatter
      • Sunburst
      • Treemap
      • Venn
      • WordCloud
      • Column
      • Pie
      • BidirectionalBar
      • Box
      • Bullet
      • Funnel
      • Heatmap
      • Histogram
      • Liquid
      • Radar
      • Stock
      • Tiny
      • Violin
      • Waterfall
      • RadialBar
  • Relation Graph Components
    • Overview
    • MindMap
    • Fishbone
    • IndentedTree
    • Dendrogram
    • OrganizationChart
    • FlowGraph
    • FlowDirectionGraph
    • NetworkGraph
    • FAQ

pack

Previous
normalizeY
Next
sample

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

概述

pack 是一种网格布局转换,它可以让图形元素在容器空间中按照行列结构紧凑排列。pack 转换主要通过以下步骤工作:

  1. 根据容器的宽高比和元素数量,计算最优的排列网格(行数和列数)
  2. 将元素按照指定方向(行优先或列优先)在网格中排列
  3. 对每个元素应用缩放和平移变换,使其适应网格单元并保持适当的间距

使用场景

pack 转换主要用于单元可视化(Unit Visualization),能够有效解决大量离散元素的布局问题,常见的使用场景如下:

  • 在有限空间内展示大量的离散元素:如数据点密集且需要避免重叠的散点图
  • 分类数据的分布展示:突出显示各类别数量差异的可视化,如人口统计分析

例如下面的案例展示了泰坦尼克号乘客按照舱位等级和生存状态的分布情况,通过 pack 转换让每个乘客点有序地排列,清晰地展示了各个类别的数量分布。

{
"autoFit": true,
"children": [
{
"type": "point",
"encode": {
"color": "survived",
"shape": "point",
"size": 3
},
"transform": [
{
"type": "pack"
}
],
"legend": {
"color": {}
},
"tooltip": {
"title": "",
"items": [
"pclass",
"survived"
]
}
}
]
}

更多的案例,可以查看单元可视化页面。

配置项

属性描述类型默认值必选
padding每个元素之间的间距,单位为像素number0
direction元素的堆叠方向row | colcol

padding

padding 用于控制每个元素之间的间距,单位为像素。增加 padding 值可以让元素之间有更明显的分隔。当值为 0 时,元素会紧密排列。

direction

direction 决定元素在网格中的堆叠方向:

  • col:列(垂直方向)堆叠
  • row:行(水平方向)堆叠

通过调整 direction,可以改变图中数据点的布局方向,以适应不同的阅读偏好和数据特点。

示例

以下案例展示了泰坦尼克号乘客性别和生存状态的分布,通过配置 pack 转换的 padding 和 direction 参数,使得结果更为直观。

{
"autoFit": true,
"shareData": true,
"children": [
{
"type": "point",
"encode": {
"color": "survived",
"shape": "point",
"size": 3
},
"transform": [
{
"type": "pack",
"padding": 5,
"direction": "row"
}
],
"legend": {
"color": {}
},
"tooltip": {
"title": "",
"items": [
"sex",
"survived"
]
}
}
]
}