<template>
  <div>
    <div id="centerChartPie" style="width: 3.375rem;height: 3.22rem;"></div>
  </div>
</template>

<script>
import echartMixins from "@/utils/resizeMixins";

export default {
  data() {
    return {
      chart: null
    };
  },
  mixins: [echartMixins],
  mounted() {
    this.draw();
  },
  methods: {
    draw() {
      // 基于准备好的dom，初始化echarts实例
      this.chart = this.$echarts.init(document.getElementById("centerChartPie"));
      //  ----------------------------------------------------------------
      
      let option = {
        tooltip: {
          trigger: 'item'
        },
        legend: {
          x: 'center',
          y: 'bottom',
          textStyle: {
            color: '#fff'  
          }
        },
        series: [
          {
            type: 'pie',
            radius: '50%',
            data: [
                { value: 1048, name: 'Search Engine' },
                { value: 735, name: 'Direct' },
                { value: 580, name: 'Email' },
                { value: 484, name: 'Union Ads' },
                { value: 300, name: 'Video Ads' }
            ],
            itemStyle: {
              normal: {
                color: function(params) {
                  var colorList = [
                    '#37a2da', '#32c5e9', '#67e0e3', '#9fe6b8', '#ffdb5c', '#ff9f7f', '#fb7293'
                  ];
                  return colorList[params.dataIndex]
                }
              }
            }
          }
        ]
      };
      this.chart.setOption(option);
    }
  },
  destroyed() {
    window.onresize = null;
  }
};
</script>

<style lang="scss" scoped>
#centreRight2Chart1 {
  margin: 0 auto;
}
</style>