【图表示例】元素-边-02

G6A Graph Visualization Framework in JavaScripthttps://g6.antv.antgroup.com/zh/examples/element/edge/#polylinehttps://g6.antv.antgroup.com/zh/examples/element/edge/#polylinehttps://g6.antv.antgroup.com/zh/examples/element/edge/#polyline

G6A Graph Visualization Framework in JavaScripthttps://g6.antv.antgroup.com/api/elements/edges/polylinehttps://g6.antv.antgroup.com/api/elements/edges/polylinehttps://g6.antv.antgroup.com/api/elements/edges/polyline

注意:初始化时,controlPoints 需要写在 edge 的 style 中

import { Graph } from "@antv/g6";

const data = {
  nodes: [
    {
      id: 'node-1',
      style: {
        x: 200,
        y: 200
      }
    },
    {
      id: 'node-2',
      style: {
        x: 350,
        y: 120
      }
    }
  ],
  edges: [
    {
      id: 'edge-1',
      source: 'node-1',
      target: 'node-2',
      style: {
        controlPoints: [[300, 120], [320, 170]]  // 线段中,控制点的位置数组
      }
    }
  ]
}

const behaviors = [
  {
    type: 'drag-element'
  }
]

const graph = new Graph({
  container: 'container',
  data,
  edge: {
    type: 'polyline', // 设置 edge.type 为 polyline 以使用折线    
    // 注意:初始化时,controlPoints 需要写在 edge 的 style 中
    style: {
      controlPoints: (d) => d.style.controlPoints,  // 控制点数组
      labelText: (d) => d.id,
      labelOffsetY: -12
    },
  },
  behaviors
})

graph.render()


 项目的创建参考 G6 详细教程,注意,node版本需要:required: { node: '>=18' }G6A Graph Visualization Framework in JavaScripthttps://g6.antv.antgroup.com/manual/getting-started/step-by-stephttps://g6.antv.antgroup.com/manual/getting-started/step-by-stephttps://g6.antv.antgroup.com/manual/getting-started/step-by-step

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值