<template>
  <div class="box">
    <tit :title="'碳排放月总量环比'">
      <!-- <div class="tit-r">单位：kw·h</div> -->
    </tit>
    <div id="mainRingPercent"></div>
  </div>
</template>

<script>
import tit from "./tit.vue";
import { getSixMonthCarbonQoq } from "@/api/energySourcesProvince/energySourcesProvince"
export default {
  data() {
    return {
    };
  },
  components: {
    tit
  },
  created() {
    this.$nextTick(() => {
      this.getData()
    })

  },
  mounted() {

  },
  methods: {
    getData() {
      getSixMonthCarbonQoq().then(res => {
        const data = res.data.data
        const sortedKeys = Object.keys(data).sort()
        // let monthData = data.map(r => Object.keys(r)[0])
        // console.log(monthData, 'monthData')
        
        let json = {}
        
        sortedKeys.forEach(e => {
          json[e] = data[e]
        })
        // let yAxisData = sortedKeys.map(r => this.$moment(r).format('M') + '月')
        // ,
        //       let arr = []
        //       for(let k in json){
        //         arr.push({
        //           {
        //         value: 12, label: { position: 'right' },
        //         itemStyle: {
        //           color: "#63D5FF"
        //         }
        //       }
        //         })
        //       }
        this.echartsInit(yAxisData)
      })
    },
    echartsInit(yAxisData) {
      const chartDom = document.getElementById('mainRingPercent');
      const myChart = this.$echarts.init(chartDom);
      const option = {
        // title: {
        //   text: 'Bar Chart with Negative Value'
        // },
        // tooltip: {
        //   trigger: 'axis',
        //   axisPointer: {
        //     type: 'shadow'
        //   }
        // },
        grid: {
          top: "10%",
          left: "10",
          right: "20",
          bottom: "0",
          containLabel: true,
        },
        xAxis: {
          type: 'value',
          // position: 'top',

          axisLabel: { formatter: '{value}%' },
          color: "#fff",
          splitLine: {
            lineStyle: {
              type: 'solid',
              color: "#9fabc1",
            }
          }
        },
        yAxis: {
          type: 'category',
          axisLine: { show: false },
          axisLabel: { show: false },
          axisTick: { show: false },
          splitLine: { show: false },
          data: yAxisData
        },
        series: [
          {
            name: 'Cost',
            type: 'bar',
            stack: 'Total',
            label: {
              show: true,
              formatter: '{b}',
              color: "#fff"
            },
            data: [
              {
                value: 12, label: { position: 'right' },
                itemStyle: {
                  color: "#63D5FF"
                }
              },
              {
                value: -12, label: { position: 'left' },
                itemStyle: {
                  color: "#1BE9BB"
                }
              },
              {
                value: 24, label: { position: 'right' },
                itemStyle: {
                  color: "#63D5FF"
                }
              },
              {
                value: -24, label: { position: 'left' },
                itemStyle: {
                  color: "#1BE9BB"
                }
              },
              {
                value: -17, label: { position: 'left' },
                itemStyle: {
                  color: "#1BE9BB"
                }
              },
              {
                value: 50, label: { position: 'right' },
                itemStyle: {
                  color: "#63D5FF"
                }
              },
            ]
          }
        ]
      };
      myChart.setOption(option);
    }
  }
};
</script>
<style lang="scss" scoped>
.box {
  width: 4.6rem;
  height: 2.55rem;
  border-radius: 4px;
  box-sizing: border-box;
  background: url("../../../../public/img/energySourcesProvince/ringPercent.png");
  background-size: 100% 100%;
  padding: 0.54rem 0.22rem 0 0.22rem;
  position: absolute;
  bottom: 0.24rem;
  left: 4.94rem;
  z-index: 29;

  .tit-r {
    font-size: 0.14rem;
    color: rgba($color: #fff, $alpha: 0.4);
    margin-top: 0.04rem;
  }

  #mainRingPercent {
    height: 1.8rem;
  }
}</style>
