<template>
  <div class="ech">
    <div id="circlecz2" style="width: 100%; height: 390px"></div>
  </div>
</template>

<script setup>
import * as echarts from "echarts";
import { ref, onMounted, defineProps,watch } from "vue";
const props = defineProps({
  data: { type: Array }
});
watch(
  () => props.data,
  () => {
    lineChartFn();
  }
);
function lineChartFn() {
  var chartDom = document.getElementById("circlecz2");
  var myChart = echarts.init(chartDom);
  var option;
  var scale = 1;
  var echartData = props.data;
  var rich = {
    yellow: {
      color: "#ffc72b",
      fontSize: 12 * scale,
      padding: [5, 4],
      align: "center"
    },
    total: {
      color: "#ffc72b",
      fontSize: 12 * scale,
      align: "center"
    },
    white: {
      color: "#fff",
      align: "center",
      fontSize: 12 * scale,
      padding: [0, 0]
    },
    blue: {
      color: "#49dff0",
      fontSize: 12 * scale,
      align: "center"
    }
  };

  option = {
    grid: {
      // show: true,
      top: "20%",
      bottom: 0,
      left: 0,
      right: "10%"
    },
    legend: {
      orient: "horizontal",
      textStyle: {
        color: "#ddd"
      }
      // left: 0,
      // top: 5
      // bottom: 5
    },
    series: [
      {
        name: "今日警情类型统计图",
        type: "pie",
        radius: ["22%", "40%"],
        hoverAnimation: false,
        color: [
          "#c487ee",
          "#deb140",
          "#49dff0",
          "#034079",
          "#6f81da",
          "#00ffb4"
        ],
        label: {
          normal: {
            formatter: function (params, ticket, callback) {
              var total = 0; //考生总数量
              var percent = 0; //考生占比
              echartData.forEach(function (value, index, array) {
                total += value.value;
              });
              percent = ((params.value / total) * 100).toFixed(1);
              return (
                "{white|" +
                params.name +
                "}\n{yellow|" +
                params.value +
                "}\n{blue|" +
                percent +
                "%}"
              );
            },
            rich: rich
          }
        },
        data: echartData
      }
    ]
  };

  option && myChart.setOption(option);
  document.getElementById("circlecz2").setAttribute("_echarts_instance_", "");
}
onMounted(() => {
  lineChartFn();
  window.onresize = function () {
    lineChartFn();
  };
});
</script>

<style lang="scss" scoped>
.ech{
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    bottom: 0;

}
</style>
