npm install --save @antv/g6
import G6 from "@antv/g6";
<template>
<div id="home"></div>
</template>
<script>
import G6 from "@antv/g6";
export default {
name: "Home",
data() {
return {
data: {
// 点集
nodes: [
{
id: "node1", // String,该节点存在则必须,节点的唯一标识
x: 100, // Number,可选,节点位置的 x 值
y: 200 // Number,可选,节点位置的 y 值
},
{
id: "node2", // String,该节点存在则必须,节点的唯一标识
x: 300, // Number,可选,节点位置的 x 值
y: 200 // Number,可选,节点位置的 y 值
}
],
// 边集
edges: [
{
source: "node1", // String,必须,起始点 id
target: "node2" // String,必须,目标点 id
}
]
},
gaph: null //实例
};
},
mounted() {
this.init();
},
methods: {
//初始化图谱方法
init() {
this.graph = new G6.Graph({
container: "home", // 指定图画布的容器 id,与第 9 行的容器对应
// 画布宽高
width: 800,
height: 500
});
// 读取数据
this.graph.data(this.data);
// 渲染图
this.graph.render();
}
}
};
</script>
<style>
.home {
width: 100%;
height: 500px;
}
</style>