logo

G6

  • 文档
  • API
  • 图表示例
  • 社区
  • 所有产品antv logo arrow
  • 5.0.47
  • 简介
  • 开始使用
    • 快速开始
    • 安装
    • 前端框架集成
      • 在 React 中使用
      • 在 Vue 中使用
      • 在 Angular 中使用
    • 详细教程
  • 图 Graph
    • Graph - 图
    • Options 配置项
    • 内置扩展
    • Extension - 扩展
  • 数据 Data
  • 元素 Element
    • 元素总览
    • 元素状态
    • 节点 Node
      • 节点总览
      • 内置节点
        • 节点通用配置项
        • Diamond 菱形
        • Donut 甜甜圈
        • Ellipse 椭圆形
        • Hexagon 六边形
        • Html HTML
        • Image 图片
        • Rect 矩形
        • Star 五角形
        • Triangle 三角形
        • Circle 圆形
      • 自定义节点
      • 使用 React 定义节点
    • 边 Edge
      • 边总览
      • 内置边
        • 边通用配置项
        • Cubic 三次贝塞尔曲线
        • CubicHorizontal 水平三次贝塞尔曲线
        • CubicVertical 垂直三次贝塞尔曲线
        • Line 直线
        • Polyline 折线
        • Quadratic 二次贝塞尔曲线
      • 自定义边
    • 组合 Combo
      • 组合总览
      • 内置组合
        • 组合配置项
        • Circle 圆形
        • Rect 矩形
      • 自定义 Combo
    • 图形 Shape
      • 图形 Shape 与 KeyShape
      • 原子 Shape 以及其属性
      • 复合 Shape 的设计与实现
  • 布局 Layout
    • 布局总览
    • 内置布局
      • 布局通用配置项
      • AntvDagre 布局
      • Circular 环形布局
      • ComboCombined 复合布局
      • CompactBox 紧凑树
      • Concentric 同心圆布局
      • D3Force 力导向布局
      • D3Force3D 3D 力导向布局
      • Dagre 布局
      • Dendrogram 生态树
      • Fishbone 鱼骨布局
      • Force 力导向布局
      • ForceAtlas2 力导向布局
      • Fruchterman 力导向布局
      • Grid 网格布局
      • Indented 缩进树
      • MDS 高维数据降维布局
      • Mindmap 脑图树
      • Radial 径向布局
      • Random 随机布局
      • Snake 蛇形布局
    • 自定义布局
  • 交互 Behavior
    • 交互总览
    • 内置交互
      • AutoAdaptLabel 标签自适应显示
      • BrushSelect 框选
      • ClickSelect 点击选中
      • CollapseExpand 展开/收起元素
      • CreateEdge 创建边
      • DragCanvas 拖拽画布
      • DragElement 拖拽元素
      • DragElementForce 力导向拖拽元素
      • FixElementSize 缩放画布时固定元素大小
      • FocusElement 聚焦元素
      • HoverActivate 悬停激活
      • LassoSelect 套索选择
      • OptimizeViewportTransform 优化视口变换
      • ScrollCanvas 滚动画布
      • ZoomCanvas 缩放画布
    • 自定义交互
  • 插件 Plugin
    • 插件总览
    • 内置插件
      • Background 背景
      • BubbleSets 气泡集
      • Contextmenu 上下文菜单
      • EdgeBundling 边绑定
      • EdgeFilterLens 边过滤镜
      • Fisheye 鱼眼放大镜
      • Fullscreen 全屏展示
      • GridLine 网格线
      • History 历史记录
      • Hull 轮廓包围
      • Legend 图例
      • Minimap 小地图
      • Snapline 对齐线
      • Timebar 时间条
      • Toolbar 工具栏
      • Tooltip 提示框
      • Watermark 水印
    • 自定义插件
  • 数据处理 Transform
    • 数据处理总览
    • 内置数据处理
      • MapNodeSize 动态调整节点大小
      • PlaceRadialLabels 径向标签
      • ProcessParallelEdges 平行边
    • 自定义数据处理
  • 主题 Theme
    • 主题总览
    • 自定义主题
    • 色板
    • 自定义色板
  • 动画 Animation
    • 动画总览
    • 自定义动画
  • 扩展阅读
    • 事件
    • 渲染器
    • 坐标系
    • 下载图片
    • 使用 iconfont
    • 使用 3D
    • 项目打包
  • 版本特性
    • 新版本特性
    • 升级到 5.0
  • 常见问题
  • 参与贡献

原子 Shape 以及其属性

上一篇
图形 Shape 与 KeyShape
下一篇
复合 Shape 的设计与实现

Resources

Ant Design
Galacea Effects
Umi-React 应用开发框架
Dumi-组件/文档研发工具
ahooks-React Hooks 库

社区

体验科技专栏
seeconfSEE Conf-蚂蚁体验科技大会

帮助

GitHub
StackOverflow

more products更多产品

Ant DesignAnt Design-企业级 UI 设计语言
yuque语雀-知识创作与分享工具
EggEgg-企业级 Node 开发框架
kitchenKitchen-Sketch 工具集
GalaceanGalacean-互动图形解决方案
xtech蚂蚁体验科技
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

G6 中的元素(节点/边)是由一个或多个 图形 Shape 组成,主要通过自定义节点或自定义边时在 render 方法中使用 upsert 添加,G6 中支持以下的图形 Shape:

  1. Circle - 圆形
  2. Ellipse - 椭圆
  3. Rect - 矩形
  4. HTML - HTML元素
  5. Image - 图片
  6. Line - 线
  7. Path - 路径
  8. Polygon - 多边形
  9. Polyline - 折线
  10. Text - 文本

各图形 Shape 的通用属性

BaseShapeStyle

属性描述类型必选
xx 坐标number✓
yy 坐标number✓
width宽度number✓
height高度number✓
fill填充颜色string | Pattern | null
stroke描边颜色string | Pattern | null
opacity整体透明度number | string
fillOpacity填充透明度number | string
strokeOpacity描边透明度number | string
lineWidth线宽度number | string
lineCap线段端点样式butt | round | square
lineJoin线段连接处样式miter | round | bevel
lineDash虚线配置number | string | (string | number)[]
lineDashOffset虚线偏移量number
shadowBlur阴影模糊程度number
shadowColor阴影颜色string
shadowOffsetX阴影 X 方向偏移number
shadowOffsetY阴影 Y 方向偏移number
cursor鼠标样式,CSS 的 cursor 选项都支持string
zIndex渲染层级number
visibility可见性visible | hidden

示例:

const shape = BaseShape.upsert(
// 指定图形 key,需要保证在同一个自定义元素类型中保持唯一性
'shape',
'circle',
{
cx: 100,
cy: 100,
r: 50,
fill: 'blue',
},
container,
);

各图形 Shape 的通用方法

attr()

设置或获取实例的绘图属性。

attr(name)

获取实例的属性值。

const width = shape.attr('width');

attr(name, value)

更新实例的单个绘图属性。

attr({...})

批量更新实例绘图属性。

shape.attr({
fill: '#999',
stroke: '#666',
});

圆图形 Circle

CircleStyleProps

属性描述类型必选
cx圆心 x 坐标number | string✓
cy圆心 y 坐标number | string✓
cz圆心 z 坐标number | string
r圆的半径number | string✓
isBillboard是否启用公告牌模式(始终面向相机)boolean
isSizeAttenuation是否启用大小衰减(随视距变化大小)boolean

示例:

BaseShape.upsert(
// 指定图形 key,需要保证在同一个自定义元素类型中保持唯一性
'shape',
'circle',
{
cx: 100,
cy: 100,
r: 50,
fill: 'blue',
},
container,
);

矩形图形 Rect

RectStyleProps

属性描述类型必选
x矩形 x 坐标number | string
y矩形 y 坐标number | string
z矩形 z 坐标number
width矩形宽度number | string✓
height矩形高度number | string✓
isBillboard是否启用公告牌模式boolean
isSizeAttenuation是否启用大小衰减boolean
radius矩形圆角半径number | string | number[]

示例:

BaseShape.upsert(
// 指定图形 key,需要保证在同一个自定义元素类型中保持唯一性
'shape',
'rect',
{
x: 100,
y: 100,
width: 100,
height: 100,
radius: 8,
fill: 'blue',
},
container,
);

椭圆图形 Ellipse

EllipseStyleProps

属性描述类型必选
cx椭圆中心 x 坐标number | string✓
cy椭圆中心 y 坐标number | string✓
cz椭圆中心 z 坐标number | string
rx椭圆 x 轴半径number | string✓
ry椭圆 y 轴半径number | string✓
isBillboard是否启用公告牌模式boolean
isSizeAttenuation是否启用大小衰减boolean

示例:

BaseShape.upsert(
// 指定图形 key,需要保证在同一个自定义元素类型中保持唯一性
'shape',
'ellipse',
{
cx: 100,
cy: 100,
rx: 50,
ry: 80,
fill: 'blue',
},
container,
);

HTML DOM

HTMLStyleProps

属性描述类型必选
xHTML 元素 x 坐标number | string
yHTML 元素 y 坐标number | string
innerHTMLHTML 内容string | HTMLElement✓
widthHTML 元素宽度number | string
heightHTML 元素高度number | string

示例:

BaseShape.upsert(
// 指定图形 key,需要保证在同一个自定义元素类型中保持唯一性
'shape',
'html',
{
x: 100,
y: 100,
innerHTML: <div>content</div>,
},
container,
);

图片图形 Image

ImageStyleProps

属性描述类型必选
x图片 x 坐标number | string
y图片 y 坐标number | string
z图片 z 坐标number
src图片资源路径或 HTML 图片元素string | HTMLImageElement✓
width图片宽度number | string
height图片高度number | string
isBillboard是否启用公告牌模式boolean
isSizeAttenuation是否启用大小衰减boolean
billboardRotation公告牌模式下的旋转角度number
keepAspectRatio是否保持图片原有宽高比boolean

示例:

BaseShape.upsert(
// 指定图形 key,需要保证在同一个自定义元素类型中保持唯一性
'shape',
'image',
{
x: 100,
y: 100,
src: 'http://',
},
container,
);

直线 Line

LineStyleProps

属性描述类型必选
x1线段起点 x 坐标number✓
y1线段起点 y 坐标number✓
x2线段终点 x 坐标number✓
y2线段终点 y 坐标number✓
z1线段起点 z 坐标number
z2线段终点 z 坐标number
isBillboard是否启用公告牌模式boolean
isSizeAttenuation是否启用大小衰减boolean
markerStart线段起点的标记DisplayObject | null
markerEnd线段终点的标记DisplayObject | null
markerStartOffset起点标记的偏移量number
markerEndOffset终点标记的偏移量number

示例:

BaseShape.upsert(
// 指定图形 key,需要保证在同一个自定义元素类型中保持唯一性
'shape',
'line',
{
x1: 100,
y1: 100,
x2: 150,
y2: 150,
stroke: 'blue',
},
container,
);

路径 Path

PathStyleProps

属性描述类型必选
d路径定义字符串或数组string | PathArray✓
markerStart路径起点的标记DisplayObject | null
markerEnd路径终点的标记DisplayObject | null
markerMid路径中间点的标记DisplayObject | null
markerStartOffset起点标记的偏移量number
markerEndOffset终点标记的偏移量number
isBillboard是否启用公告牌模式boolean
isSizeAttenuation是否启用大小衰减boolean
fillRule填充规则nonzero | evenodd

示例:

BaseShape.upsert(
// 指定图形 key,需要保证在同一个自定义元素类型中保持唯一性
'shape',
'path',
{
d: 'M 0,0 L 20,10 L 20,-10 Z',
stroke: 'blue',
},
container,
);

多边形图形 Polygon

PolygonStyleProps

属性描述类型必选
points多边形的顶点数组([number, number] | [number, number, number])[]✓
markerStart多边形起点的标记DisplayObject | null
markerEnd多边形终点的标记DisplayObject | null
markerMid多边形中间点的标记DisplayObject | null
markerStartOffset起点标记的偏移量number
markerEndOffset终点标记的偏移量number
isClosed是否闭合多边形boolean
isBillboard是否启用公告牌模式boolean
isSizeAttenuation是否启用大小衰减boolean

示例:

BaseShape.upsert(
// 指定图形 key,需要保证在同一个自定义元素类型中保持唯一性
'shape',
'polygon',
{
points: [
[30, 30],
[40, 20],
[30, 50],
[60, 100],
],
fill: 'red',
},
container,
);

折线 Polyline

PolylineStyleProps

属性描述类型必选
points折线的顶点数组([number, number] | [number, number, number])[]✓
markerStart折线起点的标记DisplayObject | null
markerEnd折线终点的标记DisplayObject | null
markerMid折线中间点的标记DisplayObject | null
markerStartOffset起点标记的偏移量number
markerEndOffset终点标记的偏移量number
isBillboard是否启用公告牌模式boolean
isSizeAttenuation是否启用大小衰减boolean

示例:

BaseShape.upsert(
// 指定图形 key,需要保证在同一个自定义元素类型中保持唯一性
'shape',
'polyline',
{
points: [
[30, 30],
[40, 20],
[30, 50],
[60, 100],
],
fill: 'red',
},
container,
);

文字 Text

TextStyleProps

属性描述类型必选
x文本 x 坐标number | string
y文本 y 坐标number | string
z文本 z 坐标number | string
text文本内容number | string✓
fontSize字体大小number | string
fontFamily字体族string
fontStyle字体样式normal | italic | oblique
fontWeight字体粗细normal | bold | bolder | lighter | number
fontVariant字体变种normal | small-caps | string
textAlign文本水平对齐方式start | center | middle | end | left | right
textBaseline文本基线top | hanging | middle | alphabetic | ideographic | `bottom'
textOverflow文本溢出处理方式clip | ellipsis | string
lineHeight行高number | string
letterSpacing字间距number | string
maxLines最大行数number
textPath文本路径Path
textPathSide文本路径侧边left | right
textPathStartOffset文本路径起始偏移number | string
textDecorationLine文本装饰线string
textDecorationColor文本装饰线颜色string
textDecorationStyle文本装饰线样式solid | double | dotted | dashed | wavy
isBillboard是否启用公告牌模式boolean
billboardRotation公告牌旋转角度number
isSizeAttenuation是否启用大小衰减boolean
wordWrap是否自动换行boolean
wordWrapWidth自动换行宽度number
dxX 方向偏移number | string
dyY 方向偏移number | string

示例:

BaseShape.upsert(
// 指定图形 key,需要保证在同一个自定义元素类型中保持唯一性
'shape',
'text',
{
x: 100,
y: 100,
text: 'text',
},
container,
);

多行文字显示:

{
wordWrap: true,
wordWrapWidth: 100,
maxLines: 4,
textOverflow: 'ellipsis',
}