vue echart 绘制关系图,并加上动态指向

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: '拓扑图'
        },
        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', // 使用二维直角坐标系
            lineStyle: {
              type: 'dashed',
              width: 2,
              color: 'blue',
              curveness: 0.05 // 调节线段曲线
            },
            effect: { // 线效配置
              show: true,
              trailLength: 0.1,
              symbol: 'arrow', // 特效图形标记
              color: 'orange',
              symbolSize: 8 // 标记的大小
            },
            data: linesData
          },
          {
            type: 'graph',
            coordinateSystem: 'cartesian2d', // 使用二维直角坐标系
            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>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容