<template>
  <div class="cointan">
    <div class="title1">
      <div style="margin-left:25px;line-height: 22px;">设备使用情况</div>
    </div>
    <!-- 区域图 -->
    <div class="chart" ref="chart"></div>
  </div>
</template>

<script>
export default {
  name: 'leftCenter',
  data() {
    return {
      
    }
  },
  props: {
    msg: String
  },
  created(){
    
  },
  mounted(){
    this.getEchartData()
  },
  methods:{
    // 用电用水
    getEchartData() {
      let _this = this;
      const chart = this.$refs.chart;
      var option = null;
      const myChart = this.$echarts.init(chart);
      option = {
        color: ['#0A93ED', '#0AA992'],
        title: {
          text: ''
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#0FEBFF'
            }
          }
        },
        legend: {
          type:'scroll',
          data: ['总设备', '使用设备'],
          textStyle:{
            color:'#FFFFFF',
            fontSize:12,
          },
          // left: 460, //图例位置（可设置top,bottom,left,right）
          icon:'roundRect',//图形样式
          // itemHeight: 11, //修改icon图形大小
          // itemWidth:11,//图例图标的宽度
        },
        grid: {
          left: '1%',
          right: '8%',
          bottom: '2%',
          containLabel: true
        },
        xAxis: [
          {
            axisLabel: {
              show: true,
              height: 19,
              fontSize: 12,
              color: "#FFFFFF",//人数的颜色
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: "#2E3F44", 
              },
            },
            type: 'category',
            data: ['投影仪', '电脑', '空调', '摄像头']
          }
        ],
        yAxis: [
          {
            alignTicks: true,
            name:'',
            nameTextStyle: {
              color: "#00E0DB",
            },
            axisLabel: {
              show: true,
              height: 19,
              fontSize: 12,
              color: "rgba(255, 255, 255, 0.45)",
            },
            axisLine: {
              show: false,
              lineStyle: {
                color: "#FFFFFF",
              },
            },
            splitLine: {
              show: true,
              lineStyle: {
                color:'rgba(255, 255, 255, 0.15)'
              }
            },
            type: 'value'
          }
        ],
        series: [
          {
            name: '总设备',
            type: 'bar',
            showBackground: true,
            backgroundStyle: {
              color: 'rgba(180, 180, 180, 0.2)'
            },
            barWidth: "10%",
            itemStyle: {
              opacity: 0.8,
              color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: '#0A93ED'
                },
                {
                  offset: 1,
                  color: '#66FFFF'
                }
              ])
            },
            data: [120, 282, 111, 234, 220, 340, 310]
          },{
            name: '使用设备',
            type: 'bar',
            showBackground: true,
            backgroundStyle: {
              color: 'rgba(180, 180, 180, 0.2)'
            },
            barWidth: "10%",
            itemStyle: {
              color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: '#0AA992'
                },
                {
                  offset: 1,
                  color: '#0BE18B'
                }
              ])
            },
            data: [30, 32, 71, 264, 90, 340, 250]
          },
        ]
      };
      myChart.setOption(option);

      myChart.off("click");

      myChart.on("click", function (params) {
        // console.log(params);
        _this.$emit("openPop");
      });

      window.addEventListener("resize", function () {
        myChart.resize();
      });
      this.$on("hook:destroyed", () => {
        window.removeEventListener("resize", function () {
          chart.resize();
        });
      });
      return option;
    },
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
.cointan{
  width: 450px;
  height: 302px;
  background-image: url('../assets/index/litterbackground.png');
  background-size: 100%;
}
.title1{
  position: absolute;
  margin: 9px 0 0 10px;
  font-size: 20px;
  font-family : '优设标题黑';
  color: rgba(255, 255, 255, 1);
  font-weight: 400;
}
// 区域图
.chart{
  position: absolute;
  margin: 60px 0 0 30px;
  width: 420px;
  height: 220px;
}
</style>
