import React ,{ useEffect } from 'react';
import echarts from 'echarts/lib/echarts';
import 'echarts/lib/chart/pie';

function Pie({data}) {

  useEffect(()=>{
    if(data){
      Init(data);
    }
  },[data])

  function Init(d) {
    var huan_val = document.getElementById("Pie");
    var chart = echarts.init(huan_val);
    let option = {
      color: ["#ff9e48", "#5ea6ff", "#f8e367", "#99dfff"],
      title: {
        show:false
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        top: '5%',
        right: 'center'
      },
      series: [
        {
          name: '',
          type: 'pie',
          radius: ['40%', '70%'],
          avoidLabelOverlap: false,
          itemStyle: {
            borderRadius: 10,
            borderColor: '#fff',
            borderWidth: 2
          },
          label: {
            show: false,
            position: 'center'
          },
          emphasis: {
            label: {
              show: true,
              fontSize: '40',
              fontWeight: 'bold'
            }
          },
          labelLine: {
            show: false
          },
          data: [
            {value: d.owner && d.owner.count, name: '创建者'},
            {value: d.manager && d.manager.count, name: '管理员'},
            {value: d.developer && d.developer.count, name: '开发者'},
            {value: d.reporter && d.reporter.count, name: '报告者'}
          ]
        }
      ]
    };
    chart.setOption(option);
  }

  return(
    <div id="Pie" style={{height:"400px"}}></div>
  )
}
export default Pie;