Vue3+Antv X6流程图基本使用

安装 antv/X6

npm i @antv/x6

js 复制代码
<template>
  <div class="homes">
    <div class="Shang">上</div>
    <div class="Zhong">
      <div id="container"></div>
    </div>
    <div class="Xia">下</div>
  </div>
</template>
<script setup>
import { ref, onMounted } from "vue";
import { Graph } from "@antv/x6";

const data = {
  // 节点
  nodes: [
    {
      id: "node1", // String,可选,节点的唯一标识
      x: 40, // Number,必选,节点位置的 x 值
      y: 40, // Number,必选,节点位置的 y 值
      width: 80, // Number,可选,节点大小的 width 值
      height: 40, // Number,可选,节点大小的 height 值
      label: "hello", // String,节点标签
    },
    {
      id: "node2", // String,节点的唯一标识
      x: 160, // Number,必选,节点位置的 x 值
      y: 180, // Number,必选,节点位置的 y 值
      width: 80, // Number,可选,节点大小的 width 值
      height: 40, // Number,可选,节点大小的 height 值
      label: "world", // String,节点标签
    },
  ],
  // 边
  edges: [
    {
      source: "node1", // String,必须,起始节点 id
      target: "node2", // String,必须,目标节点 id
    },
  ],
};
let graph = null;

const chushih = () => {
  graph = new Graph({
    container: document.getElementById("container"),
    width: 800,
    height: 600,
    background: {
      color: "#f7f7f7", // 设置画布背景颜色
    },
    grid: {
      size: 20, // 网格大小 10px
      visible: true, // 渲染网格背景
    type: 'dot', // 'dot' | 'fixedDot' | 'mesh'
    // args: { 
    //   color: '#36d', // 网格线/点颜色
    //   thickness: 2,     // 网格线宽度/网格点大小
    // },
    args: [
      { 
        color: '#36d', // 主网格线颜色
        thickness: 1,     // 主网格线宽度
      },
      { 
        color: '#ff0', // 次网格线颜色
        thickness: 1,     // 次网格线宽度
        factor: 4,        // 主次网格线间隔
      },
    ],
    },
  });
  graph.fromJSON(data);
};

onMounted(() => {
  chushih();
});
</script>
  
<style lang="less" scoped>
.homes {
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  .Shang {
    width: 100%;
    height: 100px;
    background-color: burlywood;
  }

  .Zhong {
    flex: 1;
    box-sizing: border-box;
    padding: 10px;
    background-color: #d7c5c5;
  }

  .Xia {
    width: 100%;
    height: 100px;
    background-color: burlywood;
  }
}
</style>
  
相关推荐
XH华4 小时前
C语言第十一章内存在数据中的存储
c语言·开发语言
ZXT6 小时前
js基础重点复习
javascript
言兴6 小时前
秋招面试---性能优化(良子大胃袋)
前端·javascript·面试
AndrewHZ6 小时前
【python与生活】如何用Python写一个简单的自动整理文件的脚本?
开发语言·python·生活·脚本·文件整理
拉法豆粉6 小时前
在压力测试中如何确定合适的并发用户数?
java·开发语言
枯萎穿心攻击6 小时前
Unity VS UE 性能工具与内存管理
开发语言·游戏·unity·ue5·游戏引擎·虚幻·虚幻引擎
老赵的博客7 小时前
c++ 常用接口设计
开发语言·c++
binbinaijishu887 小时前
Python爬虫入门指南:从零开始的网络数据获取之旅
开发语言·爬虫·python·其他
chenglin0167 小时前
Logstash_Input插件
java·开发语言
3壹7 小时前
单链表:数据结构中的高效指针艺术
c语言·开发语言·数据结构