第二篇: VUE使用 Echarts 画关系拓扑图,并带移动迁移特效

第二篇: VUE使用 Echarts 画关系拓扑图,并带移动迁移特效

前言:需求是使用 Echarts 画关系拓扑图,并带箭头迁移特效,为了效果更加明显,已将箭头效果放大,需要使用的话,可自行调整

效果图如下:

 

1.使用 npm 安装 Echarts:

npm install echarts --save

2.注意:由于关系拓扑图在 echarts配置中,类型 type 是 'graph',其中的连接线条是不带有 迁移(effect)特效的。需要配合 type:'lines' 同时使用,'lines'带有 迁移(effect)特效的

<template>
  <div class="echart-block">
    <div style="height:50%" ref="graphchart"></div>
  </div>
</template>
<script>
import echarts from 'echarts'
export default {
  data() {
    return {
      echart: null,
      nodes: [
        {
          name: 'java',
          value: [0, 0],
          symbol: 'diamond'
        },
        {
          name: 'web',
          value: [1, 120],
          symbol: 'triangle'
        },
        {
          name: 'mysql',
          value: [1, 240]
        },
        {
          name: 'redis',
          value: [1, 360],
          symbol: 'diamond'
        }
      ],
      links: [
        {
          source: 'java',
          target: 'web',
          symbol: ['none', 'arrow'],
          label: {
            show: true,
            formatter: '×',
            padding: [0, 0, -13, 0],
            fontSize: 20
          },
          lineStyle: {
            color: 'blue',
            curveness: 0.1
          }
        }
      ],
      lines: [
        {
          coords: [
            [1, 120],
            [0, 0]
          ]
        },
        {
          coords: [
            [1, 240],
            [1, 360]
          ]
        },
        {
          coords: [
            [1, 360],
            [1, 240]
          ]
        },
        {
          coords: [
            [1, 240],
            [0, 0]
          ]
        },
        {
          coords: [
            [0, 0],
            [1, 240]
          ]
        },
        {
          coords: [[360], [0, 0]]
        },
        {
          coords: [
            [0, 0],
            [1, 360]
          ]
        },
        {
          coords: [
            [1, 360],
            [0, 0]
          ]
        }
      ]
    }
  },
  components: {
  },
  mounted() {
    this.drawChart()
  },
  methods: {
    drawChart() {
       // 角度
      for (let i = 0; i < this.nodes.length; i++) {
        this.nodes[i].angle = (360 / this.nodes.length) * i
      }
      this.echart = echarts.init(this.$refs.graphchart)
      let option = {
        title: {
          text: 'Graph+lines 拓扑图'
        },
        polar: {},
        radiusAxis: {
          show: false
        },
        angleAxis: {
          type: 'value',
          min: 0,
          max: 360,
          show: false
        },
        series: [
          {
            type: 'graph',
            coordinateSystem: 'polar',
            label: {
              show: true,
              position: 'inside',
              fontSize: 14
            },

            // layout:'circular',
            symbol: 'circle',
            symbolSize: 50,
            symbolPosition: 'start',
            nodes: this.nodes
            // links: this.links
          },
          {
            name: 'line-echart',
            type: 'lines',
            coordinateSystem: 'polar',
            zlevel: 1,
            symbol: ['none', 'arrow'],
            symbolSize: 10,
            polyline: true,
            // effect: {
            //   symbol: 'circle',
            //   show: true,
            //   symbolSize: 20,
            //   trailLength: 0.2,
            //   color: 'red',
            //   smooth: true,
            //   period: 4,
            //   loop: true
            // },
            effect: {
              show: true,
              period: 4,
              smooth: true,
              trailLength: 0.2,
              symbol: 'arrow',
              // symbol: 'circle',
              color: 'rgba(55,155,255,0.5)',
              symbolSize: 20,
              loop: true
            },
            lineStyle: {
              normal: {
                color: '#1DE9B6',
                width: 3, // 线条宽度
                opacity: 0.6, // 尾迹线条透明度
                curveness: 0.3 // 尾迹线条曲直度
              }
            },
            data: this.lines
          }
        ]
      }
      this.echart.setOption(option)
    }
  }
}
</script>

<style lang="scss" scoped>
.echart-block {
  height: 100vh;
}
</style>

3.您的支持是我最大的动力,有疑问可留言,一起学习一起进步,谢谢🙏🙏

  • 5
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
使用 Echarts 流程图,可以使用 Echarts关系图(graph)来实现。具体步骤如下: 1. 引入 Echarts 库和主题: ```html <script src="https://cdn.jsdelivr.net/npm/echarts/dist/echarts.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/echarts-gl/dist/echarts-gl.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/echarts/dist/extension/bmap.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/echarts/dist/theme/macarons.js"></script> ``` 2. 准备容器: ```html <div id="main" style="width: 100%; height: 600px;"></div> ``` 3. 初始化 Echarts 实例: ```javascript var myChart = echarts.init(document.getElementById('main'), 'macarons'); ``` 4. 设置 Echarts 的 option: ```javascript option = { tooltip: {}, legend: { data: ['流程图'], show: false }, series: [{ type: 'graph', layout: 'none', roam: true, symbolSize: 50, label: { show: true }, edgeSymbol: ['circle', 'arrow'], edgeSymbolSize: [4, 10], edgeLabel: { fontSize: 20 }, data: [{ name: '节点1', x: 300, y: 300 }, { name: '节点2', x: 800, y: 300 }, { name: '节点3', x: 550, y: 100 }, { name: '节点4', x: 550, y: 500 }], // links 表示节点之间的连线 links: [{ source: 0, target: 1, symbolSize: [5, 20], label: { show: true }, lineStyle: { width: 5, curveness: 0.2 } }, { source: 1, target: 2, label: { show: true }, lineStyle: { curveness: 0.2 } }, { source: 1, target: 3, label: { show: true }, lineStyle: { curveness: 0.2 } }] }] }; myChart.setOption(option); ``` 在以上的代码,我们使用Echarts关系图(graph)来实现流程图,通过设置节点(data)和节点之间的连线(links)来实现。同时,我们还可以设置节点和连线的样式、标签等属性来美化流程图。 以上是一个简单的示例,你可以根据实际需求修改节点和连线的数量、位置、样式等属性,来绘制出更加复杂和美观的流程图。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值