
<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="gjdjfbChart"/>
  </el-card>
</template>

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

export default {
  mixins: [resize],
  data() {
    return {
      chart: null
    }
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart(data) {
      this.chart = echarts.init(document.querySelector('#gjdjfbChart'))
      this.setOption(data)
    },
    setOption(data) {
      const source=[['告警等级','告警数量','告警占比']]
      data.forEach(item => {
        source.push([item.level,item.dataNum,item.percent])
      })
      this.chart.setOption({
        color:['#3C81FF','#FFBE29'],
        grid: {
          containLabel: true
        },
        legend: {
          left: 'center',
          bottom: '15',
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: { // 坐标轴指示器，坐标轴触发有效
            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        textStyle:{
          color:"#333333",
        },
        xAxis: {
          type: 'category',
          axisLine: {
            lineStyle:{
              color: '#333333',
            }
          }
        },
        yAxis: [{
          type: 'value',
          axisLine: {
            lineStyle:{
              color: '#333333',
            },
            onZero:false
          }
        },{
          type: 'value',
          axisLine: {
            lineStyle:{
              color: '#333333',
            },
            onZero:false
          }
        }],
        dataset:{source},
        series: [
          {
            name:'告警数量',
            yAxisIndex:0,
            type: 'line',
          },
          {
            name:'告警占比',
            yAxisIndex:1,
            type: 'bar',
          }
          ]
      })
    }
  }
}

</script>
