AntvX6-初探

前言

  antv X6 是基于 HTML 和 SVG 的图编辑引擎,提供低成本的定制能力和开箱即用的内置扩展,方便我们快速搭建 DAG 图、ER 图、流程图、血缘图等应用
官网:https://x6.antv.antgroup.com/

框架:

vue3 + vite + TS + antv x6

引依赖

首先需要在 package.json 的文件中引入依赖,博主使用的是 2.17.1

 "@antv/x6": "2.17.1"

各版本地址:https://www.yuque.com/antv/x6/bbfu6r

代码

<template>
  <div id="container"></div>
</template>
<script setup lang="ts">
import { Graph } from "@antv/x6";
import { onMounted } from "vue";
//需要在挂载后的生命周期中去使用,否则无法识别container容器
onMounted(() => {
  const graph = new Graph({
    container: document.getElementById("container"),
    width: "800",
    height: "800",
    grid: true,
  });

  graph.addNode({
    id: "a",
    x: 120,
    y: 40,
    width: 100,
    height: 40,
    attrs: {
      body: {
        fill: "#f5f5f5",	//填充
        stroke: "#d9d9d9",	//描边
      },
    },
  });

  graph.addNode({
    id: "b",
    x: 400,
    y: 260,
    width: 100,
    height: 40,
    attrs: {
      body: {
        fill: "#f5f5f5",
        stroke: "#d9d9d9",
      },
    },
  });

  graph.addEdge({
    source: "a",
    target: "b",
    vertices: [
      { x: 200, y: 200 },
      { x: 380, y: 120 },
    ],
    // https://x6.antv.vision/zh/docs/api/registry/connector#normal
    connector: { name: "normal" },
    attrs: {
      line: {
        stroke: "#722ed1",
      },
    },
  });
});
</script>

效果预览

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

若博豆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值