<address id="ttjl9"></address>

      <noframes id="ttjl9"><address id="ttjl9"><nobr id="ttjl9"></nobr></address>
      <form id="ttjl9"></form>
        <em id="ttjl9"><span id="ttjl9"></span></em>
        <address id="ttjl9"></address>

          <noframes id="ttjl9"><form id="ttjl9"></form>

          如何在網頁前端里可視化你的知識圖譜

          2020-3-15    前端達人

          如何在網頁前端里可視化你的知識圖譜
          最近費盡千辛萬苦構造了一份可以用(大概)的知識圖譜,并且把要利用知識圖譜做的領域命名實體識別和一些推薦的功能做成Web版的demo,順帶想實現一些可視化知識圖譜的功能。

          (憑啥知識圖譜就只能在Neo4j里自嗨,不能來前端show一下,歧視嗎(¬_¬))

          找了做前端圖表展示的開源庫,D3.js和Echarts都能做,我拿Echarts實現了一下功能,先看一下在現在項目里一個基于知識圖譜查詢的實際效果:
          20200314114824402.png

          接下里看看如何的實現:

          1. 首先在本地下載Echarts相關的js文件,在線引用也可以,html文件里如下引用:
           <script src="/static/js/echarts.common.min.js"></script>   
              <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts@4.5.0/dist/echarts.min.js"></script>
          
          給要展示的圖準備一個Dom:

          <!-- 為ECharts準備一個具備大小的Dom -->
              <div class = "col-md-12">
                  <div class="panel panel-default ">
                      <header class="panel-heading">
                          關系圖 :
                      </header>
                      <div class = "panel-body ">
                          <div id="graph" style="width: 100%;height:600px;"></div>
                      </div>
                  </div>
              </div>
          


          3.設置好節點和鏈接關系,這里為了簡單手寫了一個蘋果梨子和水果之間的關系,項目里采用Django框架的交互讀取查詢的結果放入節點(data)和鏈接(links)里面了:

          data = [
                  {name:'蘋果',category:1,id:0},
                  {name:'梨子',catagory:1,id:1},
                  {name:'水果',category:2,id:2}
                  ]
              links = [
                  {source:0,target:2,category:0,value:'屬于',symbolSize:10},
                  {source:1,target:2,category:0,value:'屬于',symbolSize:10}
              ]
          


          置Echarts圖:

          var myChart = echarts.init(document.getElementById('graph'));
          
              option = {
                  title: {
                      text: ''
                  },
                  tooltip: {},
                  animationDurationUpdate: 1500,
                  animationEasingUpdate: 'quinticInOut',
                  label: {
                      normal: {
                          show: true,
                          textStyle: {
                              fontSize: 12
                          },
                      }
                  },
                  legend: {
                      x: "center",
                      show: false
                  },
                  series: [
          
                      {
                          type: 'graph',
                          layout: 'force',
                          symbolSize: 45,
                          focusNodeAdjacency: true,
                          roam: true,
                          edgeSymbol: ['none', 'arrow'],
                          categories: [{
                              name: '查詢實體',
                              itemStyle: {
                                  normal: {
                                      color: "#009800",
                                  }
                              }
                          }, {
                              name: 'instance',
                              itemStyle: {
                                  normal: {
                                      color: "#4592FF",
                                  }
                              }
                          }, {
                              name: 'class',
                              itemStyle: {
                                  normal: {
                                      color: "#C71585",
                                  }
                              }
                          }],
                          label: {
                              normal: {
                                  show: true,
                                  textStyle: {
                                      fontSize: 12,
                                  },
                              }
                          },
                          force: {
                              repulsion: 1000
                          },
                          edgeSymbolSize: [4, 50],
                          edgeLabel: {
                              normal: {
                                  show: true,
                                  textStyle: {
                                      fontSize: 10
                                  },
                                  formatter: "{c}"
                              }
                          },
                          data: data,
                          links: links,
                          lineStyle: {
                              normal: {
                                  opacity: 0.9,
                                  width: 1.3,
                                  curveness: 0,
                                  color:"#262626",
                              }
                          }
                      }
                  ]
              };
              // 使用剛指定的配置項和數據顯示圖表。
              myChart.setOption(option);
          
          這樣就成功實現了一個簡單的圖譜可視化:

          20200314115929363.png



          ————————————————
          版權聲明:本文為CSDN博主「游離態GLZ不可能是金融技術宅」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
          原文鏈接:https://blog.csdn.net/qq_37477357/article/details/104857495


          日歷

          鏈接

          個人資料

          藍藍設計的小編 http://www.syprn.cn

          存檔

          亚洲va欧美va天堂v国产综合