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

Fishbone 鱼骨布局

上一篇
Dendrogram 生态树
下一篇
Force 力导向布局

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

概述

鱼骨布局是一种专门用于表示层次结构数据的图形布局方式。它通过模拟鱼骨的形状,将数据节点按照层次结构排列,使得数据的层次关系更加清晰直观。鱼骨布局特别适用于需要展示因果关系、层次结构或分类信息的数据集。

使用场景

  • 需要展示层次结构数据,如组织结构、分类体系
  • 需要展示问题分析过程,如故障分析、质量分析
  • 需要展示决策过程,如决策树、影响因素分析

在线体验

createGraph(
{
data: {
nodes: [
{
id: 'Quality',
depth: 0,
children: ['Machine', 'Method', 'Material', 'Man Power', 'Measurement', 'Milieu'],
},
{
id: 'Machine',
depth: 1,
children: ['Mill', 'Mixer', 'Metal Lathe'],
},
{
id: 'Mill',
depth: 2,
},
{
id: 'Mixer',
depth: 2,
},
{
id: 'Metal Lathe',
depth: 2,
children: ['Milling'],
},
{
id: 'Milling',
depth: 3,
},
{
id: 'Method',
depth: 1,
},
{
id: 'Material',
depth: 1,
children: ['Masonite', 'Marscapone', 'Meat'],
},
{
id: 'Masonite',
depth: 2,
children: ['spearMint', 'pepperMint', 'test1'],
},
{
id: 'spearMint',
depth: 3,
},
{
id: 'pepperMint',
depth: 3,
children: ['test3'],
},
{
id: 'test3',
depth: 4,
},
{
id: 'test1',
depth: 3,
children: ['test4'],
},
{
id: 'test4',
depth: 4,
},
{
id: 'Marscapone',
depth: 2,
children: ['Malty', 'Minty'],
},
{
id: 'Malty',
depth: 3,
},
{
id: 'Minty',
depth: 3,
},
{
id: 'Meat',
depth: 2,
children: ['Mutton'],
},
{
id: 'Mutton',
depth: 3,
},
{
id: 'Man Power',
depth: 1,
children: ['Manager', "Master's Student", 'Magician', 'Miner', 'Magister', 'Massage Artist'],
},
{
id: 'Manager',
depth: 2,
},
{
id: "Master's Student",
depth: 2,
},
{
id: 'Magician',
depth: 2,
},
{
id: 'Miner',
depth: 2,
},
{
id: 'Magister',
depth: 2,
children: ['Malpractice'],
},
{
id: 'Malpractice',
depth: 3,
},
{
id: 'Massage Artist',
depth: 2,
children: ['Masseur', 'Masseuse'],
},
{
id: 'Masseur',
depth: 3,
},
{
id: 'Masseuse',
depth: 3,
},
{
id: 'Measurement',
depth: 1,
children: ['Malleability'],
},
{
id: 'Malleability',
depth: 2,
},
{
id: 'Milieu',
depth: 1,
children: ['Marine'],
},
{
id: 'Marine',
depth: 2,
},
],
edges: [
{
source: 'Quality',
target: 'Machine',
},
{
source: 'Quality',
target: 'Method',
},
{
source: 'Quality',
target: 'Material',
},
{
source: 'Quality',
target: 'Man Power',
},
{
source: 'Quality',
target: 'Measurement',
},
{
source: 'Quality',
target: 'Milieu',
},
{
source: 'Machine',
target: 'Mill',
},
{
source: 'Machine',
target: 'Mixer',
},
{
source: 'Machine',
target: 'Metal Lathe',
},
{
source: 'Metal Lathe',
target: 'Milling',
},
{
source: 'Material',
target: 'Masonite',
},
{
source: 'Material',
target: 'Marscapone',
},
{
source: 'Material',
target: 'Meat',
},
{
source: 'Masonite',
target: 'spearMint',
},
{
source: 'Masonite',
target: 'pepperMint',
},
{
source: 'Masonite',
target: 'test1',
},
{
source: 'pepperMint',
target: 'test3',
},
{
source: 'test1',
target: 'test4',
},
{
source: 'Marscapone',
target: 'Malty',
},
{
source: 'Marscapone',
target: 'Minty',
},
{
source: 'Meat',
target: 'Mutton',
},
{
source: 'Man Power',
target: 'Manager',
},
{
source: 'Man Power',
target: "Master's Student",
},
{
source: 'Man Power',
target: 'Magician',
},
{
source: 'Man Power',
target: 'Miner',
},
{
source: 'Man Power',
target: 'Magister',
},
{
source: 'Man Power',
target: 'Massage Artist',
},
{
source: 'Magister',
target: 'Malpractice',
},
{
source: 'Massage Artist',
target: 'Masseur',
},
{
source: 'Massage Artist',
target: 'Masseuse',
},
{
source: 'Measurement',
target: 'Malleability',
},
{
source: 'Milieu',
target: 'Marine',
},
],
},
node: {
type: 'rect',
style: {
size: [32, 32],
// fill: () => randomColor(),
label: false,
labelFill: '#262626',
labelFontFamily: 'Gill Sans',
labelMaxLines: 2,
labelMaxWidth: '100%',
labelPlacement: 'center',
labelText: (d) => d.id,
labelWordWrap: true,
},
},
edge: {
type: 'polyline',
style: {
lineWidth: 3,
},
},
behaviors: ['drag-canvas', 'zoom-canvas', 'drag-element'],
autoFit: 'view',
layout: {
type: 'fishbone',
direction: 'RL',
hGap: 50,
vGap: 50,
getRibSep: () => 60,
},
},
{ width: 600, height: 400 },
(gui, graph) => {
const options = {
type: 'fishbone',
direction: 'RL',
hGap: 50,
vGap: 50,
getRibSep: 60,
};
const optionFolder = gui.addFolder('Fishbone Layout Options');
optionFolder.add(options, 'type').disable(true);
optionFolder.add(options, 'direction', ['RL', 'LR']);
optionFolder.add(options, 'hGap', 20, 100, 10);
optionFolder.add(options, 'vGap', 20, 100, 10);
optionFolder.add(options, 'getRibSep', 30, 100, 10);
optionFolder.onChange(async ({ property, value }) => {
graph.setLayout(
Object.assign({}, graph.getLayout(), {
[property]: property === 'getRibSep' ? () => value : value,
}),
);
await graph.layout();
// 调整 direction 后部分node可能会溢出屏幕,重新执行下fitView
if (property === 'direction') {
graph.fitView();
}
});
},
);

基本用法

const graph = new Graph({
layout: {
type: 'fishbone',
direction: 'LR',
hGap: 50,
vGap: 50,
getRibSep: () => 60,
},
});

配置项

属性描述类型默认值必选
type布局类型fishbone-✓
direction排布方向,RL 从右到左,鱼头在右;LR 从左到右,鱼头在左RL | LRRL
hGap水平间距number-
vGap垂直间距number-
getRibSep获取鱼骨间距(node: NodeData) => number() => 60
width布局宽度number-
height布局高度number-
nodeSize节点大小number | [number, number] | [number, number, number] | ((node: NodeData) => number | [number, number] | [number, number, number])-
isLayoutInvisibleNodes不可见节点是否参与布局,当 preLayout 为 true 时生效boolean-
nodeFilter参与该布局的节点(node: NodeData) => boolean-
preLayout使用前布局,在初始化元素前计算布局,不适用于流水线布局boolean-

代码示例

基础用法

最简单的配置方式:

import { Graph, treeToGraphData } from '@antv/g6';
const graph = new Graph({
layout: {
type: 'fishbone',
},
autoFit: 'view',
data: treeToGraphData({
nodes: [
{ id: 'root', data: { label: 'Root' } },
{ id: 'child1', data: { label: 'Child 1' } },
{ id: 'child2', data: { label: 'Child 2' } },
{ id: 'child3', data: { label: 'Child 3' } },
],
edges: [
{ id: 'e1', source: 'root', target: 'child1' },
{ id: 'e2', source: 'root', target: 'child2' },
{ id: 'e3', source: 'root', target: 'child3' },
],
}),
edge: {
type: 'polyline',
style: {
lineWidth: 3,
},
},
behaviors: ['drag-canvas'],
});

效果如下:

createGraph(
{
layout: {
type: 'fishbone',
},
autoFit: 'view',
data: {
nodes: [
{
id: 'Quality',
depth: 0,
children: ['Machine', 'Method', 'Material', 'Man Power', 'Measurement', 'Milieu'],
},
{
id: 'Machine',
depth: 1,
children: ['Mill', 'Mixer', 'Metal Lathe'],
},
{
id: 'Mill',
depth: 2,
},
{
id: 'Mixer',
depth: 2,
},
{
id: 'Metal Lathe',
depth: 2,
children: ['Milling'],
},
{
id: 'Milling',
depth: 3,
},
{
id: 'Method',
depth: 1,
},
{
id: 'Material',
depth: 1,
children: ['Masonite', 'Marscapone', 'Meat'],
},
{
id: 'Masonite',
depth: 2,
children: ['spearMint', 'pepperMint', 'test1'],
},
{
id: 'spearMint',
depth: 3,
},
{
id: 'pepperMint',
depth: 3,
children: ['test3'],
},
{
id: 'test3',
depth: 4,
},
{
id: 'test1',
depth: 3,
children: ['test4'],
},
{
id: 'test4',
depth: 4,
},
{
id: 'Marscapone',
depth: 2,
children: ['Malty', 'Minty'],
},
{
id: 'Malty',
depth: 3,
},
{
id: 'Minty',
depth: 3,
},
{
id: 'Meat',
depth: 2,
children: ['Mutton'],
},
{
id: 'Mutton',
depth: 3,
},
{
id: 'Man Power',
depth: 1,
children: ['Manager', "Master's Student", 'Magician', 'Miner', 'Magister', 'Massage Artist'],
},
{
id: 'Manager',
depth: 2,
},
{
id: "Master's Student",
depth: 2,
},
{
id: 'Magician',
depth: 2,
},
{
id: 'Miner',
depth: 2,
},
{
id: 'Magister',
depth: 2,
children: ['Malpractice'],
},
{
id: 'Malpractice',
depth: 3,
},
{
id: 'Massage Artist',
depth: 2,
children: ['Masseur', 'Masseuse'],
},
{
id: 'Masseur',
depth: 3,
},
{
id: 'Masseuse',
depth: 3,
},
{
id: 'Measurement',
depth: 1,
children: ['Malleability'],
},
{
id: 'Malleability',
depth: 2,
},
{
id: 'Milieu',
depth: 1,
children: ['Marine'],
},
{
id: 'Marine',
depth: 2,
},
],
edges: [
{
source: 'Quality',
target: 'Machine',
},
{
source: 'Quality',
target: 'Method',
},
{
source: 'Quality',
target: 'Material',
},
{
source: 'Quality',
target: 'Man Power',
},
{
source: 'Quality',
target: 'Measurement',
},
{
source: 'Quality',
target: 'Milieu',
},
{
source: 'Machine',
target: 'Mill',
},
{
source: 'Machine',
target: 'Mixer',
},
{
source: 'Machine',
target: 'Metal Lathe',
},
{
source: 'Metal Lathe',
target: 'Milling',
},
{
source: 'Material',
target: 'Masonite',
},
{
source: 'Material',
target: 'Marscapone',
},
{
source: 'Material',
target: 'Meat',
},
{
source: 'Masonite',
target: 'spearMint',
},
{
source: 'Masonite',
target: 'pepperMint',
},
{
source: 'Masonite',
target: 'test1',
},
{
source: 'pepperMint',
target: 'test3',
},
{
source: 'test1',
target: 'test4',
},
{
source: 'Marscapone',
target: 'Malty',
},
{
source: 'Marscapone',
target: 'Minty',
},
{
source: 'Meat',
target: 'Mutton',
},
{
source: 'Man Power',
target: 'Manager',
},
{
source: 'Man Power',
target: "Master's Student",
},
{
source: 'Man Power',
target: 'Magician',
},
{
source: 'Man Power',
target: 'Miner',
},
{
source: 'Man Power',
target: 'Magister',
},
{
source: 'Man Power',
target: 'Massage Artist',
},
{
source: 'Magister',
target: 'Malpractice',
},
{
source: 'Massage Artist',
target: 'Masseur',
},
{
source: 'Massage Artist',
target: 'Masseuse',
},
{
source: 'Measurement',
target: 'Malleability',
},
{
source: 'Milieu',
target: 'Marine',
},
],
},
edge: {
type: 'polyline',
style: {
lineWidth: 3,
},
},
behaviors: ['drag-canvas'],
},
{ width: 600, height: 400 },
);

实际案例

  • Fishbone布局