vue echart 繪制關(guān)系圖,并加上動(dòng)態(tài)指向

1713420777249.png

代碼如下:

<template>
  <div id="graphEchart" style="width: 800px;height: 400px;" />
</template>

<script>
import * as echarts from 'echarts'
export default {
  data() {
    return {
      graphChart: null
    }
  },
  mounted() {
    this.graphEchart = echarts.init(document.getElementById('graphEchart'))
    this.drawEchart()
  },
  methods: {
    drawEchart() {
      const nodeData = [
        { name: 'Node111', value: [500, 1000] },
        { name: 'Node2', value: [500, 0] },
        { name: 'Node3', value: [300, 0] },
        { name: 'Node4', value: [700, 0] }
      ]
      const linesData = [
        {
          coords: [
            [500, 1000],
            [500, 0]
          ]
        },
        {
          coords: [
            [500, 0],
            [500, 1000]
          ]
        },
        {
          coords: [
            [700, 0],
            [500, 1000]
          ]
        },
        {
          coords: [
            [300, 0],
            [500, 0]
          ]
        }
      ]
      const options = {
        backgroundColor: 'gray',
        title: {
          title: '拓?fù)鋱D'
        },
        xAxis: {
          min: 0,
          max: 1000,
          show: false,
          type: 'value'
        },
        yAxis: {
          min: 0,
          max: 1000,
          show: false,
          type: 'value'
        },
        series: [
          {
            type: 'lines',
            polyLine: true,
            coordinateSystem: 'cartesian2d', // 使用二維直角坐標(biāo)系
            lineStyle: {
              type: 'dashed',
              width: 2,
              color: 'blue',
              curveness: 0.05 // 調(diào)節(jié)線段曲線
            },
            effect: { // 線效配置
              show: true,
              trailLength: 0.1,
              symbol: 'arrow', // 特效圖形標(biāo)記
              color: 'orange',
              symbolSize: 8 // 標(biāo)記的大小
            },
            data: linesData
          },
          {
            type: 'graph',
            coordinateSystem: 'cartesian2d', // 使用二維直角坐標(biāo)系
            layout: 'none',
            symbolSize: 50,
            roam: true,
            label: {
              show: true
            },
            edgeSymbol: ['circle', 'arrow'],
            edgeSymbolSize: [4, 10],
            edgeLabel: {
              fontSize: 15
            },
            data: nodeData
          }
          
        ]
      }
      this.graphEchart.setOption(options)
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容