pieEchartCopy.vue 3.33 KB
<template>
  <div class="contain">
    <!-- :style="{ width: width, height: height }" -->
    <div class="echart" ref="myChart" :style="{ width: width, height: height }"></div>
  </div>
</template>

<script>
export default {
  props: {
    width: {
      type: String,
      // default: () => {
      //   return "";
      // },
      default: ''
    },
    height: {
      type: String,
      default: ''
    },
    topDataObj: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      pieData: [
        { value: 0, name: '未加企微' },
        { value: 0, name: '已加企微' }
      ]
    }
  },
  mounted() {
    this.$nextTick(() => {
      console.log(this.topDataObj, '饼图')
      this.pieData[0].value = this.topDataObj.entmicroNotAddCustomerCount
      this.pieData[1].value = this.topDataObj.entmicroAddCustomerCount
      this.initChart()
    })
  },
  methods: {
    initChart() {
      // 基于准备好的dom,初始化echarts实例
      let myChart = this.$echarts.init(this.$refs.myChart)
      // 绘制图表
      myChart.setOption({
        /*   title: {
          text: '客户总数',
          subtext: '已加和未加企微的所有潜客和已购买客户',
          left: '20',
          top: '20',
          textStyle: {
          },
          subtextStyle: {
            fontSize: '12px',
            fontWeight: '400',
            color: '#808080'
          }
        },*/
        tooltip: {
          trigger: 'item', //模板变量有 {a}、{b}、{c}、{d},分别表示系列名,数据名,数据值,百分比。{d}数据会根据value值计算百分比
          formatter: '{b} : {c}人 ({d}%)'
        },
        color: ['#5850FF', '#FFB21F'],
        // legend: {
        //   orient: "vertical",
        //   bottom: "bottom",
        // },
        series: [
          {
            name: '客户总数',
            type: 'pie',
            // radius: '118px',
            center: ['50%', '36%'],
            radius: ['32%', '48%'],
            stillShowZeroSum: false,
            data: this.pieData,
            // data: [
            //   { value: 3000, name: '未加企微' },
            //   { value: 7000, name: '已加企微' }
            // ],
            // emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)',
              //下面控制显示饼状图上百分比
              normal: {
                // color: function (params) {
                //   //自定义颜色
                //   var colorList = [
                //     "#00FFFF",
                //     "#00FF00"

                //   ];
                //   return colorList[params.dataIndex];
                // },

                label: {
                  position: 'inner',
                  formatter: '{d}%',
                  // show: true,
                  color: '#fff',
                  // fontSize:14,
                  // formatter: "{b}:\n{c}人({d}%)",
                  // fontWeight: "bold",
                  // color: '#666666'
                  // color: ["#1296db", "#d42378"],
                },
                labelLine: { show: true }
              }
            }

            // },
          }
        ]
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.contain {
  position: relative;
  z-index: 9;
}
</style>