<template>
  <div class="chart" :id="id"></div>
</template>

<script lang="ts">
import { Component, Prop, Vue, Watch } from 'vue-property-decorator'
import * as echarts from 'echarts';
type EChartsOption = echarts.EChartsOption;

@Component
export default class Pie01 extends Vue {
  id=this.randomString();

  mounted(){
    this.init()
  }

  randomString(){
    const str = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    let result = '';
    for (let i = 10; i > 0; --i) 
      result += str[Math.floor(Math.random() * str.length)];
    return result;
  }

  init(){
    let chartDom:any = document.getElementById(this.id);
    let myChart = echarts.init(chartDom);
    let option: EChartsOption;

    option = {
      title: {
        text: '区域月订单量',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        orient: 'vertical',
        left: 'left'
      },
      series: [
        {
          name: '当前数据',
          type: 'pie',
          radius: '50%',
          data:
          [
            {name:'北京市', value:3000},
            {name:'广西壮族自治区', value:1000},
            {name:'广东省',value:5500},
            {name:'湖南省',value:2500},
            {name:'贵州省',value:1300},
            {name:'四川省',value:2600},
            {name:'上海市',value:3600}
          ],
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          },
          label:{
            formatter: '{b}: {d}' + '%'
          }
        }
      ]
    };

    option && myChart.setOption(option);
  }
}
</script>

<style lang="scss" scoped>
.chart{
  height: 100%;
  width: 100%;
}
</style>