<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'

const animationDuration = 3000

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: ''
          },
          tooltip:{trigger:'item',backgroundColor:'#f2f2f2'},
          legend: {
            data:[]
          },
           splitArea : {
                       show : false,
                       areaStyle : {
                           color: 'rgba(255,0,0,0)', // 图表背景的颜色
                       },
                   },

              // 设置雷达图中间射线的颜色
                      axisLine: {
                          lineStyle: {
                              color: 'rgba(131,141,158,.1)',
                              },
                      },
            splitLine : {
                        show : true,
                        lineStyle : {
                            width : 1,
                            color : 'rgba(131,141,158,.1)', // 设置网格的颜色
                        },
                    },
          radar: {
            // shape: 'circle',
            indicator: [
              { name: 'Sales', max: 6500 },
              { name: 'Administration', max: 16000 },
              { name: 'Information Technology', max: 30000 },
              { name: 'Customer Support', max: 38000 },
              { name: 'Development', max: 52000 },
              { name: 'Marketing', max: 25000 }
            ]
          },
          series: [
            {
              name: 'Budget vs spending',
              type: 'radar',
              areaStyle: {
                          normal: {
                              width: 1,
                              opacity: 0.2,
                          },
                      },
              data: [
                {
                  value: [4200, 3000, 20000, 35000, 50000, 18000],
                  name: 'Allocated Budget',
                  // 设置区域边框和区域的颜色
                                  itemStyle: {
                                      normal: {
                                          color: 'rgba(255,171,43,1)',
                                          lineStyle: {
                                              color: 'rgba(255,171,43,0.17)',
                                          },
                                      },
                                      },
                  areaStyle: {
                              color: 'rgba(255,171,43,1)'
                            }
                },

              ]
            }
          ]
      })
    }
  }
}
</script>
