<template>
  <div>
    <div ref='ringChart' class="ringChart" style="width:290px;height:290px"></div>
  </div>
</template>

<script>
import { listSubType } from "@/api/conf/subType";
import * as echarts from 'echarts';
export default {
  name: 'RingChart',
  data() {
    return {
      // 总数量
      total:0,
      chart:null,
      option:null
    }
  },
  mounted() {
    this.getList();
    this.ringChart()
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    ringChart() {
      var chartDom = this.$refs.ringChart
      this.chart = echarts.init(chartDom)
      this.option = {
        tooltip: {
          trigger: 'item',
        },
        legend: {
          top: '5%',
          left: 'center',
        },
        title: {
          text: '算法总数',
          subtext:this.total,
          textStyle: {
            fontSize: 18, 
            fontWeight: 400, 
          },
          subtextStyle:{
            fontSize: 26, 
            fontWeight: 700, 
            color: "rgb(50,197,233)",
          },
          left: 'center', // 文字水平居中
          top: '40%', // 文字垂直居中
        },
        series: [
          {
            name: '算法',
            type: 'pie',
            radius: ['45%', '70%'],
            avoidLabelOverlap: false,
            label: {
              show: false,
              position: 'center',
            },
            emphasis: {
              label: {
                show: true,
                fontSize: 24,
                fontWeight: 'bold',
              },
            },
            labelLine: {
              show: false,
            },
            data: [
              { value: 17, name: '数据处理' },
              { value: 9, name: '特征提取' },
              { value: 11, name: '故障预测' },
            ],
          },
        ],
      }
      this.chart.on('mousemove',  (params) => {
        if (params.data) {
          this.option.title.text = ' '
          this.option.title.subtext = ' '
          this.chart.setOption(this.option)
        }
      })

      this.chart.on('mouseout',  () => {
        this.option.title.text = '算法总数'
        this.option.title.subtext = this.total
        this.chart.setOption(this.option)
      })
      this.option && this.chart.setOption(this.option)
    },
    // 获取总条数
    getList() {
      this.loading = true;
      this.queryParams={pageNum:1,pageSize:100}
      listSubType(this.queryParams).then(response => {
        // this.subTypeList = response.rows;
        this.total = response.total;
        this.loading = false;
        this.ringChart()
      });
    },
    
  },
}
</script>

<style scoped>
</style>