美文网首页
vue单文件引用vis.js的Network示例

vue单文件引用vis.js的Network示例

作者: Felicity0512 | 来源:发表于2019-06-27 15:10 被阅读0次

    安装vis

    npm install vis
    

    单文件中引入

    以Network为例

    <template>
      <div id="visualization"></div>
    </template>
    
    <script>
    //按需引入
    import { DataSet, Network } from 'vis/index-network';
    
    export default {
      name: 'VisNetWork',
      data () {
        return {
          network: null
        }
      },
      mounted(){
        this.create();
      },
      methods: {
        create () {
          // 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('#visualization');
    
          // provide the data in the vis format
          var data = {
              nodes: nodes,
              edges: edges
          };
          var options = {};
    
          // initialize your network!
          this.network = new Network(container, data, options);
        }
      }
    }
    </script>
    

    一个最简单的示例就完成了。

    相关文章

      网友评论

          本文标题:vue单文件引用vis.js的Network示例

          本文链接:https://www.haomeiwen.com/subject/imrrcctx.html