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

<script>
import * as echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')

      this.chart.setOption({
         title: {
          text: '包装线02',
          subtext: '本月产量',
          left: 'center'
        },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
          left: 'center',
          bottom: '10',
          data: ['榄菊檀香型精品线香蚊香(60装)','榄菊加大盘高级型蚊香优惠装(30装)',
                 '榄菊高级型蚊香3+1家庭特惠装(18装)',
                '榄菊牌小盘高级型黑蚊香(中天繁体)(60装)（出口）',
                '榄菊牌小盘高级型蚊香筒装(繁体版)(6装)(出口)'
                ]
        },
        series: [
          {
            name: 'WEEKLY WRITE ARTICLES',
            type: 'pie',
            roseType: 'radius',
            radius: [15, 95],
            center: ['50%', '38%'],
            data: [
              { value: 320, name: '榄菊檀香型精品线香蚊香(60装)' },
              { value: 240, name: '榄菊加大盘高级型蚊香优惠装(30装)' },
              { value: 149, name: '榄菊高级型蚊香3+1家庭特惠装(18装)' },
              { value: 100, name: '榄菊牌小盘高级型黑蚊香(中天繁体)(60装)（出口）' },
              { value: 59, name: '榄菊牌小盘高级型蚊香筒装(繁体版)(6装)(出口)' }
            ],
            animationEasing: 'cubicInOut',
            animationDuration: 2600
          }
        ]
      })
    }
  }
}
</script>
