vis 动态添加数据

借鉴两篇文章作出了demo效果

vue用vis插件如何实现网络拓扑图_vue.js_脚本之家

src/App.vue · yaofengqiao/vis-demo - Gitee.com

mounted () {
    this.getList();
  },
  methods: {
    getList() {
      allRelation(this.queryParams).then(response => {
          var edgeList =response;
          var edges = new Array(edgeList.length);
           for (var j = 0; j < edgeList.length; j++) {

            // console.log("edgeList[j].topfrom::"+edgeList[j].topfrom);
            // console.log("edgeList[j].topto::"+edgeList[j].topto);
            edges[j] = {'from': edgeList[j].topfrom, 'to': edgeList[j].topto};


          }
             this.edges = edges;
        })
      allName(this.queryParams).then(response => {
            
        var nodeList = response;
        var nodes = new Array(nodeList.length)
        for (var i = 0; i < nodeList.length; i++) {

          // console.log("nodeList[i].topImg::"+nodeList[i].topImg);

          nodes[i] = {'id': nodeList[i].topId, 'label': nodeList[i].topZName}

          if(nodeList[i].topType=='orderer'){
            nodes[i].image=orderer
          }
          if(nodeList[i].topType=='channel'){
            nodes[i].image=passage
          }
          if(nodeList[i].topType=='organization'){
            nodes[i].image=organization
          }
          if(nodeList[i].topType=='peer'){
            nodes[i].image=orderer
          }
        }
        this.nodes = new vis.DataSet(nodes);


        
       
        var data = {
          nodes: this.nodes,
          edges: this.edges
        }
        var options = {
           nodes:{
              shape: 'image',//设置图片
            },
            layout: {
          hierarchical: {
            direction: 'LR', // 层次结构的方向
            sortMethod: 'directed', // 节点层级的算法
            // shakeTowards: 'roots', // 根节点排列在顶部
            levelSeparation: 550, // 每层之间最小距离
            nodeSpacing: 100, // 节点距离
          }
        },
        interaction: {
          dragNodes: false, //是否能拖动节点
          dragView: false, //是否能拖动画布
          hover: true, //鼠标移过后加粗该节点和连接线
          multiselect: true, //按 ctrl 多选
          selectable: true, //是否可以点击选择
          selectConnectedEdges: true, //选择节点后是否显示连接线
          hoverConnectedEdges: true, //鼠标滑动节点后是否显示连接线
          zoomView: false //是否能缩放画布
        },
        }
        var container = document.getElementById('mynetwork')
        var network = new vis.Network(container, data, options);
      });
      },

  • 9
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值