<template>
  <div class="iot-pie">
    <div class="title"></div>
    <div class="pie-box">
      <img src="../../../assets/imgs/IOTImage/pie-bg.png" />
      <div class="pie-content" ref="pieRef"></div>
    </div>
  </div>
</template>

<script setup>
import { onMounted, ref } from "vue";
import * as echarts from "echarts";

const pieRef = ref(null);
const option = {
  tooltip: {
    trigger: "item",
  },
  series: [
    {
      name: "Access From",
      type: "pie",
      radius: ["85%", "97%"],
      avoidLabelOverlap: false,
      labelLine: {
        show: false,
      },
      label: {
        show: false,
        position: "center",
      },
      data: [
        {
          value: 60.25,
          name: "Search Engine",
          itemStyle: {
            normal: {
              color: {
                type: "linear",
                colorStops: [
                  { offset: 0, color: "#44C8FF" },
                  { offset: 1, color: "#009CFF" },
                ],
              },
              borderRadius: "50%",
              borderWidth: 5,
            },
          },
        },
        {
          value: 60.25,
          name: "Direct",
          itemStyle: {
            normal: {
              color: {
                type: "linear",
                colorStops: [
                  { offset: 0, color: "#04BE65" },
                  { offset: 1, color: "#00F5C5" },
                ],
              },
              borderRadius: "50%",
              borderWidth: 5,
            },
          },
        },
        {
          value: 45.25,
          name: "Email",
          itemStyle: {
            normal: {
              color: {
                type: "linear",
                colorStops: [
                  { offset: 0, color: "#EADC5C" },
                  { offset: 1, color: "#FFF100" },
                ],
              },
              borderRadius: "50%",
              borderWidth: 5,
            },
          },
        },
        {
          value: 40.25,
          name: "Union Ads",
          itemStyle: {
            normal: {
              color: {
                type: "linear",
                colorStops: [
                  { offset: 0, color: "#1CE2FF" },
                  { offset: 1, color: "#00FFF1" },
                ],
              },
              borderRadius: "50%",
              borderWidth: 5,
            },
          },
        },
        {
          value: 25.25,
          name: "Video Ads",
          itemStyle: {
            normal: {
              color: {
                type: "linear",
                colorStops: [
                  { offset: 0, color: "#E57A29" },
                  { offset: 1, color: "#FFC163" },
                ],
              },
              borderRadius: "50%",
              borderWidth: 5,
            },
          },
        },
        {
          value: 14.25,
          name: "Video Ads",
          itemStyle: {
            normal: {
              color: {
                type: "linear",
                colorStops: [
                  { offset: 0, color: "#9589F4" },
                  { offset: 1, color: "#BDA9FB" },
                ],
              },
              borderRadius: "50%",
              borderWidth: 5,
            },
          },
        },
      ],
    },
  ],
};
onMounted(() => {
  const myChart = echarts.init(pieRef.value);
  option && myChart.setOption(option);
});
</script>

<style scoped lang="scss">
.iot-pie {
  width: 100%;
  height: 180px;
  padding-left: 30px;
  padding-top: 20px;
  .pie-box {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    position: relative;
    width: 315px;
    height: 230px;
    img {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
    }
    .pie-content {
      position: relative;
      left: -7px;
      top: -20px;
      width: 180px;
      height: 180px;
      z-index: 255;
    }
  }
}
</style>
