eachart环形图的使用

13 篇文章 0 订阅

在列表页添加 环形图

在这里插入图片描述

 <div class="other">
    <echarts :id="'pie'+i" ref="echarts" :precent="item.stageValue*100" :color="viewClass(item.status,'color')" height="1.32rem" />
      <span>{{item.stageDesc}}</span>
 </div>
 this.$nextTick(() => {
   for (let i = 0; i < this.businessData.length; i++) {
       this.$refs.echarts[i].pieInit()
      }
    })
<template>
  <div class="echarts-wrap">
    <div :id="id" :height="height" :style="{height:height}" class="echarts" />
    <span v-if="precent">{{precent}}%</span>
  </div>
</template>

<script>

export default {
  name: 'Echart',
  props: {
    id: {
      type: String,
      default: () => {
        return ''
      }
    },
    height: {
      type: String,
      default: () => {
        return '0.8rem'
      }
    },
    xData: {
      type: Array,
      default: () => {
        return []
      }
    },
    precent: {
      type: Number,
      default: 0
    },
    color: ''
  },
  data () {
    return {
      resizeTimer: null,
      myChart: null
    }
  },
  watch: {
    myChart (val) {
      if (!val) return

      window.addEventListener('resize', () => {
        if (this.resizeTimer) clearTimeout(this.resizeTimer)
        this.resizeTimer = setTimeout(() => {
          this.myChart.resize()
        }, 100)
      })
    }
  },
  methods: {
    pieColor (precent) {
      let data
      switch (precent) {
        case 0:
          data = [{
            value: 100,
            name: '已丢单',
            itemStyle: {
              normal: { color: this.color }
            }
          }]
          break
        case 100:
          data = [{
            value: 100,
            name: '已签单',
            itemStyle: {
              normal: { color: this.color }
            }
          }]
          break
        default:
          data = [{
            value: 100 - precent,
            name: '商机意向',
            itemStyle: {
              normal: { color: '#fff' }
            }
          }, {
            value: precent,
            name: '跟进中',
            itemStyle: {
              normal: { color: this.color }
            }
          }]
      }
      return data
    },
    pieInit () {
      const growUp = this.$echarts.init(document.getElementById(this.id))
      this.myChart = growUp

      const option = {
        legend: {
          orient: 'vertical',
          left: 10,
          data: []
        },
        series: [
          {
            name: '订单数',
            type: 'pie',
            radius: ['60%', '100%'],
            avoidLabelOverlap: false,
            hoverAnimation: false,
            label: {
              show: false,
              position: 'center'
            },
            emphasis: {
              itemStyle: {
                shadowBlur: 0,
                shadowOffsetX: 0
              }
            },
            labelLine: {
              show: false
            },
            data: this.pieColor(this.precent)
          }
        ]
      }
      growUp.setOption(option, true)
    }
  }
}

</script>

<style lang='scss' scoped>
.echarts-wrap {
  position: relative;
  width: 1.32rem;
  height: 1.32rem;
}
.echarts {
  width: 100%;
}
span {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.24rem;
}
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值