vue用vis插件实现网络拓扑图
安装引入visnpm安装visnpm install vis引入visimport { DataSet, Network } from 'vis';vis使用示例methods:{globalTrace () {// create an array with nodesvar nodes = new DataSet([{id: 1, label: 'Node 1'},{id: 2, label:
·
安装引入vis
- npm安装vis
npm install vis
- 引入vis
import { DataSet, Network } from 'vis';
vis使用示例
methods:{
globalTrace () {
// create an array with nodes
var nodes = new DataSet([
{id: 1, label: 'Node 1'},
{id: 2, label: 'Node 2'},
{id: 3, label: 'Node 3'},
{id: 4, label: 'Node 4'},
{id: 5, label: 'Node 5'}
]);
// create an array with edges
var edges = new DataSet([
{from: 1, to: 3},
{from: 1, to: 2},
{from: 2, to: 4},
{from: 2, to: 5}
]);
// create a network
var container = document.querySelector('#global_trace_content');
// provide the data in the vis format
var data = {
nodes: nodes,
edges: edges
};
var options = {
//节点样式
nodes: {
shape: "box",//设置节点node样式为矩形
fixed:true,//节点node固定不可移动
font: {
color: "white", //字体的颜色
size: 30 //显示字体大小
},
scaling: {
min: 16,
max: 32 //缩放效果比例
},
},
//连接线的样式
edges: {
color: {
color: "rgb(97, 168, 224)",
highlight: "rgb(97, 168, 224)",
hover: "green",
inherit: "from",
opacity: 1.0
},
font: {
align: "top",//连接线文字位置
},
smooth: true, //是否显示方向箭头
arrows: {to : true },//箭头指向from节点
},
layout: {
//以分层方式定位节点
hierarchical: {
direction: "LR",//分层排序方向
sortMethod: "directed",//分层排序方法
levelSeparation:400//不同级别之间的距离
},
},
interaction: {
navigationButtons: true,
// hover: true, //鼠标移过后加粗该节点和连接线
selectConnectedEdges: false, //选择节点后是否显示连接线
},
};
// initialize your network!
this.network = new Network(container, data, options);
this.network.on("click",e=> this.showDetail(e));//单击事件
this.network.on("doubleClick",e=> this.enterService(e))//双击事件
},
},
mounted(){
this.globalTrace()
}
vis官方文档
更多推荐
已为社区贡献3条内容
所有评论(0)