<template>
  <div id="main2" style="width: 100%; height: 100%"></div>
</template>
<script>
import echarts from "echarts";
export default {
  name: "pieCamera",
  mounted() {
    this.showMain();
  },
  methods: {
    showMain() {
      // 基于准备好的dom，初始化echarts实例
      var myChart = echarts.init(document.getElementById("main2"));

      var data = {
        name: "摄像头",
        value: [39],
        // nAmount: 566557.14,
      };

      var color = ["#C8E4FF", "#0483FF", "#0483FF"];

      var title=data.value[0];
      var per="%"

      // 指定图表的配置项和数据
      var option = {


        title: {
          text: '{a|'+ title +'}{b|'+ per +'}',
          textStyle: {
            rich:{
                a: {
                    fontSize: 30,
                    color: color[2],
                    fontFamily: "impact",
                },
                b: {
                    fontSize: 16,
                    fontFamily: "impact",
                     color: color[2],
                },
            }
          },
          subtext: '异常率',
          subtextStyle: {
              color: '#fff',
              fontSize:'12',
          },
          left: "center",
          top: "37%",    //aa圈内标题的位置
        },
      
        
        graphic: [
          {
            type: "text",
            z: 100,
            left: "center",
            top: "90%",   // aa 底下标题w在容器里的位置
            style: {
              fill: "#fff",
              text: data.name,
              // text: [
              //     '横轴表示温度，单位是°C',
              //     '纵轴表示高度，单位是km',
              //     '右上角有一个图片做的水印',
              //     '这个文本块可以放在图中各',
              //     '种位置'
              // ].join('\n'),
              font: "1.6rem Microsoft YaHei",     // aa 底下标题字体大小
            },
          },
        ],
        tooltip: {    //aa 手指移入
          formatter: function (params) {
            return (
              '<span style="color: #fff;">占比：' + params.value + "%</span>"
            );
          },
        },

        angleAxis: {
          max: 100,
          clockwise: false, // 逆时针
          // 隐藏刻度线
          show: false,
          startAngle: 90,
        },


        radiusAxis: {
          type: "category",
          show: true,
          axisLabel: {
            show: false,
          },
          axisLine: {
            show: false,
          },
          axisTick: {
            show: false,
          },
        },


        
        polar: [
          {
            center: ["50%", "50%"], //中心点位置    aa填充圈的中心位置
            radius: "100%", //图形大小    aa填充圈的图形大小
          },
        ],
        series: [
          {
            name: "小环",
            type: "gauge",
            splitNumber: 15,
            radius: "75%",   //aa发散圈的大小
            center: ["50%", "50%"],
            startAngle: 0,
            endAngle: 359.9999,
            axisLine: {
              show: false,
            },
            axisTick: {
              show: true,
              lineStyle: {
                color: color[1],
                width: 1,    // aa发散圈的粗细
                shadowBlur: 1,
                shadowColor: color[1],
              },
              length: 8,  // aa发散圈的长度
              splitNumber: 5,  //aa发散圈每一条间隔
            },
            splitLine: {
              show: false,
            },
            axisLabel: {
              show: false,
            },
            detail: {
              show: false,
            },
          },
          {
            type: "bar",
            z: 10,
            data: data.value,
            showBackground: false,
            backgroundStyle: {
              color: color[1],
              borderWidth: 10,
              width: 10,
            },
            coordinateSystem: "polar",
            // roundCap: true,   //aa填充圈圆角
            barWidth: 7,    //aa填充圈宽度
            itemStyle: {
              normal: {
                opacity: 1,
                color: new echarts.graphic.LinearGradient(0, 0, 1, 1, [
                  {
                    offset: 0,
                    color: color[0],
                  },
                  {
                    offset: 1,
                    color: color[1],
                  },
                ]),
                shadowBlur: 5,
                shadowColor: "#2A95F9",
              },
            },
          },
          {
            type: "pie",
            name: "内层细圆环",
            radius: ["50%", "52%"],   //aa内层细圆环
             center: ["50%", "50%"],
            startAngle: 120,
            hoverAnimation: false,
            clockWise: true,
            barWidth: 1,
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 1, 1, [
                  {
                    offset: 0,
                    color: color[0],
                  },
                  {
                    offset: 1,
                    color: color[1],
                  },
                ]),
              },
            },
            tooltip: {
              show: false,
            },
            label: {
              show: false,
            },
            data: [100],
          },
        ],
      };

      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option);
      window.addEventListener("resize", function() {
    myChart.resize();
  });
    },
  },
};
</script>