<template>
  <div class="piebox" id="circlecz">
    <!-- <div class="cirbox"></div> -->
  </div>
</template>

<script setup>
import * as echarts from "echarts";
import { ref, onMounted, watch, defineProps } from "vue";
const props = defineProps({
  data: { type: Array },
  key: Number,
  totalCount: Number
});
watch(
  () => props.key,
  () => {
    lineChartFn();
  },
  {
    deep: true
  }
);
const count = ref(0);
function lineChartFn() {
  var chartDom = document.getElementById("circlecz");
  var myChart = echarts.init(chartDom);
  var option;
  var scale = 1;

  var rich = {
    yellow: {
      color: "#ffc72b",
      fontSize: 14 * scale,
      padding: [5, 4],
      align: "center"
    },
    total: {
      color: "#ffc72b",
      fontSize: 14 * scale,
      align: "center"
    },
    white: {
      color: "#fff",
      align: "center",
      fontSize: 14 * scale,
      padding: [0, 0]
    },
    blue: {
      color: "#49dff0",
      fontSize: 14 * scale,
      align: "center"
    }
  };

  option = {
    backgroundColor: "rgba(0,0,0,0)",
    // title:{
    //     show:true,
    //     text: '使用次数'
    // },
    graphic: {
      type: 'text',
      // left: 'center',
      left: '55%',
      top: '50%',
      style: {
        text:
          String(
            '总数:' + props.totalCount
          ).replace(/(\d)(?=(?:\d{6})+$)/g, '$1.'),
        // String(this.circularGraph.sum.number).replace(/(\d)(?=(?:\d{6})+$)/g, '$1.'),
        textAlign: 'center',
        fill: '#333',
        width: 30,
        height: 30,
        fontSize: 14
      }
    },
    legend: {
      orient: 'vertical',
      left: "left"
    },
    series: [

      {
        name: "使用次数",
        type: "pie",
        left: 100,
        radius: ['40%', '60%'],
        padAngle: 5,
        avoidLabelOverlap: true,
        hoverAnimation: true,
        clockwise: true,
        startAngle: 120,
        itemStyle: {
          borderRadius: 5
        },
        color: [
          '#f9031d', '#ee4f6087', '#dc6405',
          '#f79f599c', '#e8e507', '#e1df57a1', '#0766ee', '#5891e38c'
        ],
        label: {
          normal: {
            formatter: function (params, ticket, callback) {
              return params.value;
            },
            rich: rich
          }
        },
        data: props.data
      }
    ]
  };
  option && myChart.setOption(option);
  window.onresize = function () {
    myChart.resize();
  };
  document.getElementById("circlecz").setAttribute("_echarts_instance_", "");
}
onMounted(() => {
  lineChartFn();
});
</script>

<style lang="scss" scoped>
.piebox {
  width: 100%;
    height: calc(100% - 30px);
  position: relative;
  text-align: center;
}

.count {
  position: absolute;
  bottom: 59%;
  text-align: center;
  color: var(--el-color-primary);
  right: 19%;
}

.canvas {
  left: 6px !important;
  top: 39px !important;
}
</style>
