echartCircle.vue 1.29 KB
<template>
  <div :id="coustomId" class="coustom-main"></div>
</template>

<script>
import * as echarts from 'echarts'
export default {
  name: 'echartCircle',

  props: {
    coustomId: {
      type: String,
      default: ''
    },
    bgColor1: {
      type: String,
      default: ''
    },
    bgColor2: {
      type: String,
      default: ''
    },
    coustomCount: {
      type: String
    }
  },

  data() {
    return {}
  },
  watch: {
    coustomCount() {
      this.getEchart()
    }
  },
  methods: {
    getEchart() {
      const chartDom = document.getElementById(this.coustomId)
      const myChart = echarts.init(chartDom)
      let option
      option = {
        series: [
          {
            type: 'pie',
            radius: ['40%', '70%'],
            hoverAnimation: false,
            avoidLabelOverlap: false,
            color: [this.bgColor1, this.bgColor2],
            label: {
              show: false,
              position: 'center'
            },
            labelLine: {
              show: false
            },
            data: [{ value: 100 - this.coustomCount }, { value: this.coustomCount }]
          }
        ]
      }

      option && myChart.setOption(option)
    }
  }
}
</script> 

<style lang="scss" scoped>
.coustom-main {
  width: 74px;
  height: 74px;
}
</style>