使用Neovis.js+vue2可视化demo

使用 Neovis.js 可视化 demo

参考:

https://gitcode.net/mirrors/neo4j-contrib/neovis.js?utm_source=csdn_github_accelerator

1,Prepare Neo4j

LOAD CSV WITH HEADERS FROM 'https://raw.githubusercontent.com/mathbeveridge/asoiaf/master/data/asoiaf-all-edges.csv'
AS row
MERGE (src:Character {name: row.Source})
MERGE (tgt:Character {name: row.Target})
MERGE (src)-[r:INTERACTS]->(tgt)
  ON CREATE SET r.weight = toInteger(row.weight)
LOAD CSV WITH HEADERS FROM 'https://raw.githubusercontent.com/johnymontana/neovis.js/master/examples/data/got-centralities.csv'
AS row
MATCH (c:Character {name: row.name})
SET c.community = toInteger(row.community),
c.pagerank = toFloat(row.pagerank)

Install

Neovis.js can be installed via npm:

npm install --save neovis.js

vue2界面

<template>
  <div>
    <div id="viz"></div>
    <!-- <div style="height: 100%" ref="Screen">
      <div class="left" id="viz1" ref="viz1"></div>
    </div> -->
  </div>
</template>

<script>
import NeoVis from "neovis.js";
var neo4j = require("neo4j-driver");

export default {
  // eslint-disable-next-line vue/multi-word-component-names
  name: "Neo4j",
  data() {
    return {
      neoViz: {},
    };
  },
  mounted() {
    var query = "MATCH (n:Person) RETURN n LIMIT 2";
    this.executeCypher(query);
    this.draw();
  },
  methods: {
    executeCypher(query) {
      this.echartsNode = []; //节点数组
      this.nodesRelation = []; //关系线数组
      this.category = []; //echarts图例数据数
      // 创建实例
      this.driver = neo4j.driver("bolt://localhost:7687");
      console.log(
        "🚀 ~ file: AuthorArticleSearch.vue ~ line 46 ~ mounted ~  this.drive",
        this.driver
      );

      let me = this;
      me.records = [];
      this.clearAll = true;
      let session = this.driver.session();
      if (query == "") return;
      session
        .run(query, {})
        .then((result) => {
          me.clearAll = false;
          me.records = result.records;
          console.log("neo4j 查询结果", result);

          session.close();
          me.closeLoading(false);
        })
        .catch(function (error) {
          console.log("Cypher 执行失败!", error);
          me.driver.close();
        });
    },
    closeLoading(status) {
      console.log("closeLoading", status);
    },
    draw() {
      const config = {
        containerId: "viz",
        neo4j: {
          serverUrl: "bolt://localhost:7687",
          // serverUser: "neo4j",
          // serverPassword: "sorts-swims-burglaries",
        },
        labels: {
          Character: {
            label: "name",
            value: "pagerank",
            group: "community",
            // [NeoVis.NEOVIS_ADVANCED_CONFIG]: {
            //   function: {
            //     title: (node) => viz.nodeToHtml(node, ["name", "pagerank"]),
            //   },
            // },
          },
        },
        relationships: {
          INTERACTS: {
            value: "weight",
          },
        },
        initialCypher: "MATCH (n)-[r:INTERACTS]->(m) RETURN * LIMIT 25",
      };

      this.neoViz = new NeoVis(config);
      this.neoViz.render();
    },
  },
};
</script>

<style scoped>
#viz {
  width: 900px;
  height: 700px;
  border: 1px solid lightgray;
  font: 22pt arial;
}
</style>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值