0


Neo4j+Neovis+Vue3:前端连接数据库渲染

Neovis(github):https://github.com/neo4j-contrib/neovis.js

Neovis配置文档:neovis.js (neo4j-contrib.github.io)

一、安装Neo4j

参考文章:neo4j下载安装配置步骤-CSDN博客

二、Neovis使用

1.npm引入

  1. npm install --save neovis.js

2.挂载节点及配置

  1. <template>
  2. <div class="title">可视化知识图谱</div>
  3. <div class="neo-box">
  4. <div ref="viz" id="viz" style="width: 100%; height: 100%"></div>
  5. </div>
  6. </template>
  7. <script setup>
  8. import NeoVis from "neovis.js/dist/neovis.js";
  9. import { onMounted, ref } from "vue";
  10. const config = ref({
  11. containerId: "viz",
  12. neo4j: {
  13. serverUrl: "bolt://localhost:7687",
  14. serverUser: "neo4j",
  15. serverPassword: "12345679",
  16. },
  17. labels: {
  18. Author: {label: "name",},
  19. Dynasty: { label: "name" },
  20. Poem: { label: "name" },
  21. },
  22. relationships: {},
  23. initialCypher: "MATCH (n)-[r]->(m) RETURN n, r, m", //查询语句
  24. });
  25. onMounted(() => {
  26. const vis = new NeoVis(config.value);
  27. vis.render();
  28. });
  29. </script>

最终效果图:鼠标滚动放大,节点可拖拽

三、踩坑经历

1.查询节点

查询语句MATCH (n) return n返回的只有节点,不显示关系

  1. initialCypher: "MATCH (n) return n"

使用以下语句查询关系

  1. initialCypher: "MATCH (n)-[r]->(m) RETURN n, r, m"

2.配置项不需要打引号“”

参考有些文章对labels的配置里的字段加了双引号“”,配置不需要双引号,而且prettier会报错。。。

错误配置:

  1. labels: {
  2. "节点标签": {
  3. "label": "显示的节点属性",
  4. ......
  5. }
  6. }

正确配置:

  1. labels: {
  2. 节点标签: {
  3. label: "显示的节点属性",
  4. ......
  5. }
  6. }
标签: 前端 数据库 neo4j

本文转载自: https://blog.csdn.net/agaric303/article/details/140906368
版权归原作者 电饭宝_ 所有, 如有侵权,请联系我们删除。

“Neo4j+Neovis+Vue3:前端连接数据库渲染”的评论:

还没有评论