实现人物关系图还在用Echarts吗?快试试relation-graph

关于relation-graph

支持Vue和React的 关联关系图谱组件,可以展示如组织机构图谱、股权架构图谱、集团关系图谱等知识图谱,可提供多种图谱布局,包括树状布局、中心布局、力学布局自动布局等。官网

安装使用

一,通过nodejs开发vue的使用者
1, 引入relation-graph
// 注意:relation-graph支持Vue2、Vue3、React, 但引入的包名称都是【relation-graph】
npm install --save relation-graph
2, 示例代码:
通过调整以下示例代码中的options、nodes、lines的配置实现不同的展示效果,还可以通过事件在图谱中实现交互式功能,更多的示例
2.1.2 Vue2:

<template>
   <div>
     <div style="height:calc(100vh - 50px);">
        <RelationGraph ref="seeksRelationGraph" :options="graphOptions" :on-node-click="onNodeClick" :on-line-click="onLineClick" />
     </div>
   </div>
 </template>

 <script>
// relation-graph也支持在main.js文件中使用Vue.use(RelationGraph);这样,你就不需要下面这一行代码来引入了。
 import RelationGraph from 'relation-graph'
 export default {
   name: 'Demo',
   components: { RelationGraph },
   data() {
     return {
       graphOptions: {
         allowSwitchLineShape: true,
         allowSwitchJunctionPoint: true,
         defaultJunctionPoint: 'border'
         // 这里可以参考"Graph 图谱"中的参数进行设置
       }
     }
   },
   mounted() {
     this.showSeeksGraph()
   },
   methods: {
     showSeeksGraph() {
       const __graph_json_data = {
         rootId: 'a',
         nodes: [
           { id: 'a', text: 'A', borderColor: 'yellow' },
           { id: 'b', text: 'B', color: '#43a2f1', fontColor: 'yellow' },
           { id: 'c', text: 'C', nodeShape: 1, width: 80, height: 60 },
           { id: 'e', text: 'E', nodeShape: 0, width: 150, height: 150 }
         ],
         lines: [
           { from: 'a', to: 'b', text: '关系1', color: '#43a2f1' },
           { from: 'a', to: 'c', text: '关系2' },
           { from: 'a', to: 'e', text: '关系3' },
           { from: 'b', to: 'e', color: '#67C23A' }
         ]
       }
       // 以上数据中的node和link可以参考"Node节点"和"Link关系"中的参数进行配置 
       this.$refs.seeksRelationGraph.setJsonData(__graph_json_data, (seeksRGGraph) => {
         // Called when the relation-graph is completed 
       })
     },
     onNodeClick(nodeObject, $event) {
       console.log('onNodeClick:', nodeObject)
     },
     onLineClick(lineObject, $event) {
       console.log('onLineClick:', lineObject)
     }
   }
 }
 </script>

VUE3

<template>
  <div>
    <div style="border: #efefef solid 1px; height: calc(100vh - 100px);width: 100%;">
      <relation-graph ref="relationGraph$" :options="options" />
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue'
import RelationGraph from 'relation-graph/vue3'
const relationGraph$ = ref<RelationGraph>()
const options = {
  defaultExpandHolderPosition: 'right'
}
onMounted(() => {
  const jsonData = {
    rootId: 'a',
    nodes: [
      { id: 'a', text: 'a', },
      { id: 'b', text: 'b', },
      { id: 'c', text: 'c', },
      { id: 'd', text: 'd', },
      { id: 'e', text: 'e', },
      { id: 'f', text: 'f', },
    ],
    lines: [
      { from: 'a', to: 'b', },
      { from: 'a', to: 'c', },
      { from: 'a', to: 'd', },
      { from: 'a', to: 'e', },
      { from: 'a', to: 'f', },
    ],
  }
  relationGraph$.value.setJsonData(jsonData)
})
</script>

二,通过CDN方式使用
2.1.2 使用Vue2:


建议使用 CDN 引入的用户在链接地址上锁定版本,以免将来升级时受到非兼容性更新的影响。锁定版本的方法请查看 unpkg.com。

2.1.3 使用Vue3:


建议使用 CDN 引入的用户在链接地址上锁定版本,以免将来升级时受到非兼容性更新的影响。锁定版本的方法请查看 unpkg.com。

效果图
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

总结
本文只是简单的讲述了relation-graph的使用安装,relation-graph使用支持Vue和React的 关联关系图谱组件,可以展示如组织机构图谱、股权架构图谱、集团关系图谱等知识图谱,可提供多种图谱布局,包括树状布局、中心布局、力学布局自动布局等

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue3 Relation Graph 是一个基于 Vue3 和 D3.js 的关系图谱组件库,可以用于展示和操作复杂的关系网络数据。它提供了丰富的功能和交互效果,其中包括实现线条悬浮框的功能。 要实现线条悬浮框,你可以按照以下步骤进行操作: 1. 安装依赖:首先,在你的 Vue 项目中安装 vue3-relation-graph 组件库。可以使用 npm 或者 yarn 进行安装。 2. 导入组件:在需要使用关系图谱的组件中,导入 vue3-relation-graph 组件。 ```javascript import { RelationGraph } from 'vue3-relation-graph'; ``` 3. 准备数据:准备好你的关系网络数据,包括节点和边的信息。可以根据你的需求,将数据存储在组件的 data 中或者从后端获取。 4. 使用组件:在模板中使用 RelationGraph 组件,并将准备好的数据传递给组件。 ```html <template> <RelationGraph :nodes="nodes" :edges="edges" /> </template> ``` 5. 自定义线条悬浮框:通过配置 RelationGraph 组件的 props,你可以自定义线条悬浮框的内容和样式。可以使用 slot 来自定义线条悬浮框的内容。 ```html <template> <RelationGraph :nodes="nodes" :edges="edges"> <template #edge-tooltip="{ edge }"> <div class="tooltip"> <p>{{ edge.label }}</p> <p>{{ edge.weight }}</p> </div> </template> </RelationGraph> </template> ``` 在上面的例子中,我们使用了一个名为 `edge-tooltip` 的 slot 来自定义线条悬浮框的内容。在这个 slot 中,我们可以访问到当前悬浮的边的信息,并根据需要进行展示。 这样,当用户将鼠标悬停在关系图谱的线条上时,就会显示自定义的线条悬浮框。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值