<template>
  <div class="container7" @click="fn(ryxxcjqkUrl)">
    <div ref="bar" class="bar"></div>
  </div>
</template>
      
<script>
import {getZzmmqk} from '@/api/jcxxxt.js'
export default {
  data (){
    return{
            data:[],
            name:[],
            value:[],
            ryxxcjqkUrl:"http://219.147.99.164:8082/population/route/bigdata/list-basepopulationinfo.html",
    }
  },
  created(){
     this.getZzmmqk()
  },
  methods: {
    fn(url) {
      layer.open({
        type: 2,
        content: url,
        area: ["80%", "80%"],
        title: "",
      });
    },
    gr() {
      let myChart = this.$echarts.init(this.$refs.bar);
      var tootipTimer = null;
      let option = {
        xAxis: {
          type: "category",
          data:this.name ,
          axisTick: {
            alignWithLabel: true,
            lineStyle: {
              color: "#fff",
            }, // x轴刻度的颜色
          },

          axisLine: {
            lineStyle: {
              color: '#fff '
            }
          },
          axisLabel: {
            textStyle: {
              color: "#fff",
            },
            rotate: 30,
            interval: 0
          },
        },
        yAxis: {
          type: "value",
          axisTick: {
            show: false, //刻度线
          },
          axisLabel: {
            textStyle: {
              color: "#fff",
            },

          },
        },
        grid: {
          left: "4%",
          right: "6%",
          bottom: "6%",
          top: "8%",
          containLabel: true,
        },
        tooltip: {
          show: true,
          borderWidth: 0,
          position: "right",
          // label:{
          //    backgroundColor: "#fff",
          //    width:'120%',
          //    height:'88px'
          // },
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
          formatter: "{b}" + "&nbsp" + ":" + "&nbsp" + "{c}" + "人",
        },
        series: [
          {
            data: this.value,
            type: "bar",
            color: "#f10909",
            barWidth: "60%",
            // emphasis :{
            //     itemStyle:{
            //     color:"rgba(255,255,255,0.2)"
            //     }
            // },
            label: {
              show: true,
              position: "top",
              formatter: "{c}" + "人",
              textStyle: {
                fontSize: "12",
                color: "#fff",
                fontWeight: 100,
              },
            },
          },
        ],
      };
      myChart.setOption(option);
      let sizeFun = function () {
        myChart.resize();
      };
      window.addEventListener("resize", sizeFun);
      tootipTimer && tootipTimer.clearLoop();
      tootipTimer = null;
      // 调用轮播的方法
      tootipTimer = window.loopShowTooltip(myChart, option, {
        interval: 2000, // 轮播间隔时间
        loopSeries: true, // 是否开启轮播循环
      });
    },
    async getZzmmqk() {
      try {
        const res = await getZzmmqk()
        //  console.log(res);
         this.data = res.data.list
         this.data.forEach(item =>{
          this.name.push(item.name)
          this.value.push(item.value)
         })
         this.$nextTick(() => {
                    this.gr();
                })
      } catch (error) {
        console.log('数据获取失败');
      }
    }
  },
  mounted() {
    // this.gr();
  },
};
</script>
      
<style scoped lang="scss">
.container7 {
  //    border: 1px solid #00ffff; 
  width: 23.6458vw;
  height: 24.5161vh;

  .bar {
    width: 23.6458vw;
    height: 24.5161vh;
  }
}
</style>