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
  • 常见问题
  • 参与贡献

新版本特性

上一篇
项目打包
下一篇
升级到 5.0

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 5.0 重新设计了图配置范式,在保证能力完善的基础上,优化配置项结构,更加直观、易于理解。

仅需快速了解基本核心概念,即可快速上手 G6,快速实现图可视化。

😰 4.0 配置项 嵌套结构复杂,语义化能力较弱

{
defaultNode: {
size: 30,
style: {
fill: 'steelblue',
stroke: '#666',
lineWidth: 1
},
labelCfg: {
style: {
fill: '#fff',
}
}
},
nodeStateStyles: {
hover: {
fill: 'lightsteelblue'
}
},
modes: {
default: ['zoom-canvas', 'drag-canvas', 'drag-node'],
},
}

😄 5.0 配置项 结构清晰,易于理解

{
node: {
style: {
size: 30,
fill: 'steelblue',
stroke: '#666',
lineWidth: 1
labelFill: '#fff',
},
state: {
hover: {
fill: 'lightsteelblue'
}
}
},
behaviors: ['zoom-canvas', 'drag-canvas', 'drag-element'],
}

🔨 全新 API 设计

G6 5.0 采用了更加简洁、易用的 API 设计,更加符合现代前端框架的设计风格。

🌲 合并图与树图

树图本质上是一种单向无环图,G6 5.0 融合了图与树图的设计,降低了理解和使用成本。

现在,你可以在 G6 中直接使用 Graph 来实例化绘制树图,而不需要再使用 TreeGraph,仅需指定布局为树图布局即可。

此外,G6 提供了 treeToGraphData 工具方法,帮助你快速将树图数据转换为图数据。

import { Graph, treeToGraphData } from '@antv/g6';
const data = {
id: 'root',
children: [
{ id: 'node1', children: [{ id: 'node1-1' }, { id: 'node1-2' }] },
{ id: 'node2', children: [{ id: 'node2-1' }, { id: 'node2-2' }] },
],
};
const graph = new Graph({
container: 'container',
layout: {
type: 'compact-box',
direction: 'TB',
},
data: treeToGraphData(data),
edge: {
type: 'cubic-vertical',
},
});
graph.render();

createGraph(
{
autoFit: 'view',
data: g6.treeToGraphData({
id: 'root',
children: [
{ id: 'node1', children: [{ id: 'node1-1' }, { id: 'node1-2' }] },
{ id: 'node2', children: [{ id: 'node2-1' }, { id: 'node2-2' }] },
],
}),
layout: {
type: 'compact-box',
direction: 'TB',
},
node: {
style: {
ports: [{ placement: 'center' }],
},
},
edge: {
type: 'cubic-vertical',
},
},
{ width: 200, height: 200 },
);

🌆 多渲染器支持

G6 5.0 采用了新一代设计的 @antv/g 渲染引擎,提供了 Canvas SVG WebGL 多种渲染器支持,并且分层画布支持不同渲染器的混合使用。

import { Renderer } from '@antv/g-webgl';
import { Graph } from '@antv/g6';
const graph = new Graph({
// ... 其他配置
// 使用 WebGL 渲染器
renderer: () => new Renderer(),
});

🚀 高性能布局

G6 5.0 采用了全新布局引擎,部分布局提供 Rust 实现,提供了更高性能的布局计算。另有布局支持 WebGPU 加速。

🚀 高性能布局需要安装 @antv/layout-wasm 包

import { ForceAtlas2Layout, initThreads, supportsThreads } from '@antv/layout-wasm';
import { Graph, register, ExtensionCategory } from '@antv/g6';
register(ExtensionCategory.LAYOUT, 'forceatlas2-wasm', ForceAtlas2Layout);
const supported = await supportsThreads();
const threads = await initThreads(supported);
const graph = new Graph({
// ... 其他配置
layout: {
type: 'forceatlas2-wasm',
threads,
// ... 其他布局配置
},
});

GPU 加速布局需要安装 @antv/layout-gpu 包

import { FruchtermanLayout } from '@antv/layout-gpu';
import { Graph, register, ExtensionCategory } from '@antv/g6';
register(ExtensionCategory.LAYOUT, 'fruchterman-gpu', FruchtermanLayout);
const graph = new Graph({
// ... 其他配置
layout: {
type: 'fruchterman-gpu',
// ... 其他布局配置
},
});

🎨 多主题机制

G6 5.0 内置了亮色、暗色两套主题,并可基于使用场景进行灵活定制,具体可参考自定义主题。

🌍 3D 大图

G6 5.0 提供了 3D 大图渲染、布局、交互能力,从 @antv/g6-extension-3d 中引入 3D 元素、渲染器、交互等注册即可使用,详见:使用 3D。

💪 插件优化增强

G6 5.0 对现有插件进行了优化增强,解除了 Graph 与插件之间的耦合,并优化配置的同时提供了更加丰富了能力。

敬请前往插件体验更多插件的能力。

💼 优化包体积

得益于 G6 5.0 良好的模块化的设计以及扩展注册机制,对于未使用的模块,不会被打包到最终的构建文件中,减小了包体积。

与 4.0 相比,UMD 包体积从 1.8 MB 减小到 0.96 MB,减小了近 50%。