Echarts 画关系拓扑图,并带移动迁移特效,基于vue

效果图如下:
在这里插入图片描述
1.安装 Echarts:

npm install echarts --save

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

vue完整代码如下(内有释义)

<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: [//箭头流动方向
        {//mysql-redis
          coords: [
            [1, 240],
            [1, 360]
          ]
        },
        {//redis-web
          coords: [
            [1, 360],
            [1, 120]
          ]
        },
        {//web-mysql
          coords: [
            [1, 120],
            [1, 240]
          ]
        },
        {//mysql-java
          coords: [
            [1, 240],
            [0, 0]
          ]
        },
        {//java-web
          coords: [
            [0, 0],
            [1, 120]
          ]
        },
        {//java-redis
          coords: [
            [0, 0],
            [1, 360]
          ]
        },
      ]
    }
  },
  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: {//移动图标设置
              show: true,
              period: 4,
              smooth: true,
              trailLength: 0.2,
              symbol: 'arrow',//箭头
              // symbol: 'circle',//原点
              // symbol: 'image://' + require('@/assets/logo.png'),//自定义图片
              color: 'rgba(55,155,255,0.5)',
              symbolSize: 15,//大小
              loop: true,//循环流动
            },
            lineStyle: {//连接线
              normal: {
                color: '#1DE9B6',
                width: 2, // 线条宽度
                opacity: 0.6, // 尾迹线条透明度
                curveness: 0.3 // 尾迹线条曲直度
              }
            },
            data: this.lines
          }
        ]
      }
      this.echart.setOption(option)
    }
  }
}
</script>
 
<style scoped>
.echart-block {
  height: 100vh;
}
</style>
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
VueEcharts 都是非常流行的前端框架和库,用于数据可视化和构建交互式应用程序。下面是如何在 Vue 中使用 Echarts 甘特的简单步骤: 1. 安装 Echarts 库 在 Vue 项目中使用 Echarts,需要先安装 Echarts 库。可以使用 npm 或 yarn 进行安装: ```npm install echarts --save``` 或 ```yarn add echarts``` 2. 导入 Echarts 库 在 Vue 组件中,需要导入 Echarts 库,并创建一个实例,例如: ```javascript import echarts from 'echarts' export default { data(){ return { chart: null } }, mounted(){ this.createChart() }, methods: { createChart(){ this.chart = echarts.init(this.$refs.chart) // 在这里配置甘特的数据和样式 } } } ``` 3. 配置甘特数据和样式 通过 Echarts 的 API,可以配置甘特的数据和样式。例如: ```javascript createChart(){ this.chart = echarts.init(this.$refs.chart) this.chart.setOption({ tooltip: { formatter: function (params) { var duration = params.value[2] - params.value[1]; return params.name + ': ' + params.value[1] + ' - ' + params.value[2] + '<br/>' + 'Duration: ' + duration + ' days'; } }, xAxis: { scale: true, min: new Date(2017, 0, 1).getTime(), max: new Date(2017, 4, 1).getTime(), type: 'time', boundaryGap : false }, yAxis: { data: ['Planning', 'Implementation', 'Testing'] }, series: [{ name: 'Project Plan', type: 'custom', renderItem: function (params, api) { var yValue = api.value(0); var start = api.coord([api.value(1), yValue]); var end = api.coord([api.value(2), yValue]); var height = api.size([0, 1])[1] * 0.6; return { type: 'rect', shape: echarts.graphic.clipRectByRect({ x: start[0], y: start[1] - height / 2, width: end[0] - start[0], height: height }, { x: params.coordSys.x, y: params.coordSys.y, width: params.coordSys.width, height: params.coordSys.height }), style: api.style() }; }, encode: { x: [1, 2], y: 0 }, data: [ ['Planning', new Date(2017, 1, 1), new Date(2017, 2, 3)], ['Implementation', new Date(2017, 2, 3), new Date(2017, 3, 20)], ['Testing', new Date(2017, 3, 20), new Date(2017, 4, 1)] ] }] }) } ``` 在这个例子中,我们通过 Echarts 的 API,指定了甘特的数据和样式。例如,我们指定了 x 轴的时间范围和 y 轴的项目阶段。然后,我们创建了一个自定义的渲染项,用于绘制甘特的条形。最后,我们将这个渲染项添加到了甘特的 series 中。 以上就是使用 VueEcharts 甘特的简单步骤。希望这个例子能够帮助你更好地理解如何在 Vue 中使用 Echarts

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值