<template>
  <div class="myChart" ref="myChart" :style="{height: height+'px'}"></div>
</template>

<script>
export default {
  data() {
    return {
    }
  },
  props: {
    height: Number
  },
  mounted() {
    this.init()
  },
  methods: {
    init() {
      let chart = this.$echarts.init(this.$refs.myChart);
      let options = {
        color: ['#80B2FF','#FFDF80'],
        legend: {
          data: [
            '告警次数',
          ]
        },
        grid: {
          left: '2%', //默认10%
          right: '2%', //默认10%
          bottom: '10%', //默认60
          top: '15%',
          containLabel: true
          //grid区域是否包含坐标轴的刻度标签
        },
        xAxis: {
          type: 'category',
          data: ['火焰告警', '烟雾告警', '水浸异常', '设备故障', '违规闯入', '行为异常']
        },
        yAxis: [
          {
            //name: '告警次数',
            type: 'value',
            nameTextStyle: {
              padding: [10, 0, 10, 15]
            },
          },
        ],
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          },
          textStyle: {
            color: '#fff',
            align: 'left',
            fontSize: 14
          },
          axisLine: {//x坐标轴轴线
            show: true,
            lineStyle: {//x坐标轴轴线样式
              color: '#000',//'#ccc' | 'rgb(128, 128, 128)' | 'rgba(128, 128, 128, 0.5)'，设置标签颜色
            }
          },
          backgroundColor: 'rgba(0,0,0,0.8)',
        },
        series: [
          {
            name: '告警次数',
            data: [120, 125, 133, 145, 170, 175],
            type: 'bar',
            backgroundStyle: {
              color: 'rgba(180, 180, 180, 0.2)'
            }
          },
        ]
      };
      chart.setOption(options);
    }
  }
}
</script>

<style lang="less" scoped>
</style>