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>
  
相关推荐
高野44015 分钟前
【高性能内存池】central cache内存回收 7
开发语言·c++
qq_5443291715 分钟前
从0学习React(1)
开发语言·前端·javascript
shiji-lu19 分钟前
针对考研的C语言学习(定制化快速掌握重点2)
c语言·开发语言·学习
cookcyq21 分钟前
React & 解释常见的 hooks: useState / useRef / useContext / useReducer
前端·javascript·react.js
IT小白322 分钟前
Vue项目开发注意事项
前端·javascript·vue.js
黄毛火烧雪下25 分钟前
React -AppVarContext.Provider 提供者组件
前端·javascript·react.js
linlinlove226 分钟前
php如何实现局部替换功能
开发语言·php
想做一只快乐的修狗26 分钟前
【React】react项目中的redux使用
前端·javascript·react.js
敲代码的鹏鹏38 分钟前
C++(string字符串、函数)
开发语言·数据结构·c++
火红的小辣椒1 小时前
PHP反序列化5(回调函数call_user_func_array)
android·开发语言·php