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

2019-06-27  本文已影响0人  Felicity0512

安装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>

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

上一篇下一篇

猜你喜欢

热点阅读