<template>
  <div
    :class="className"
    :style="{height:height,width:width}"
  />
</template>

<script>
import echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
import resize from "./mixins/resize";
import { statistics } from "@/api/index/index";
import { setTimeout } from "timers";

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: "chart"
    },
    chartDate: "",
    width: {
      type: String,
      default: "100%"
    },
    height: {
      type: String,
      default: "400px"
    }
  },
  watch: {
    chartDate(value) {
    
      this.chartDate = value;
        this.initChart();
    }
  },
  data() {
    return {
      chart: null,
      indexDate: "",
      sex: []
    };
  },
  mounted() {
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, "macarons");

      this.chart.setOption({
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        color: ["#ee6666", "#73c0de", "#fc8452"],
        legend: {
          left: "center",
          bottom: "10",
          data: ["正式党员", "预备党员","发展对象", "积极分子"]
        },
        series: [
          {
            name: "统计信息",
            type: "pie",
            roseType: "radius",
            radius: [15, 95],
            center: ["50%", "38%"],
            data: [
              { value: this.chartDate.dy_nums , name: "正式党员"+  this.chartDate.dy_nums +'人' },
              { value: this.chartDate.ybdy_nums, name: "预备党员" +  this.chartDate.ybdy_nums +'人'},
              { value: this.chartDate.ybdy_nums, name: "发展对象" +  this.chartDate.fzdx_nums +'人'},
              { value: this.chartDate.jjfz_nums, name: "积极分子" +  this.chartDate.jjfz_nums +'人'}
            ],
            animationEasing: "cubicInOut",
            animationDuration: 2600
          }
        ]
      });
    }
  }
};
</script>
