<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"
    },
    sexDate:""
  },
  watch: {
    chartDate(value) {
    
      this.chartDate = value;
    

      
      let arr=[]
      value.sex_group.map(item=>{
        arr.push({
          name:item.name +"(" + item.nums +"人)",
          value:item.nums
        })
      })
      this.sex=arr
      
      console.log(this.sex,"---------------------sex")
        this.initChart();
    }
  },
  data() {
    return {
      chart: null,
      sex: 1
    };
  },
  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"
        },
        legend: {
          orient: "vertical",
          left: "left"
        },
        color: [
          "#fac858",
          "#ee6666",
          "#73c0de",
          "#3ba272",
          "#fc8452",
          "#9a60b4",
          "#ea7ccc"
        ],
        series: [
          {
            name: "访问来源",
            type: "pie",
            radius: "50%",
            data: this.sex,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)"
              }
            }
          }
        ]
      });
    }
  }
};
</script>
