
<template>
  <el-card shadow="always" class="common-card-container common-card-container-body-no-padding">
    <div slot="header">
      <span class="card-title">设备告警占比</span>
    </div>
    <div style="height: 360px" id="sbgjzbChart"/>
  </el-card>
</template>

<style scoped lang="scss"></style>
<script>
import * as echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from '@/mixins/ems/resize'

export default {
  mixins: [resize],
  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(document.querySelector('#sbgjzbChart'), 'macarons')
      this.setOptions()
    },
    setOptions() {
      this.chart.setOption({
        color:['#FFBE29','#3C81FF','#A796FF','#FC6B69','#58F3AA'],
        tooltip: {
          trigger: 'item'
        },
        legend: {
          left: 'center',
          bottom:'10'
        },
        series: [
          {
            name: '设备告警占比',
            type: 'pie',
            radius: '50%',
            data: [
              { value: 1048, name: '数据一' },
              { value: 735, name: '数据二' },
              { value: 580, name: '数据三' },
              { value: 484, name: '数据四' },
              { value: 300, name: '数据五' }
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      })
    }
  }
}

</script>
