<template>
  <div class="container6">
    <div ref="bar" class="bar"></div>
  </div>
</template>
      
  <script>
import { getSjhdsqk } from "@/api/zhdjxt.js";
export default {
  data() {
    return {
      data: [],
      number: [],
      text: [],
    };
  },
  created() {
    this.getSjhdsqk();
  },

  methods: {
    gr() {
      let myChart = this.$echarts.init(this.$refs.bar);
      var tootipTimer = null;
      let option = {
        xAxis: {
          type: "category",
          data: this.text,
          axisTick: {
            alignWithLabel: true,
          },
          axisLabel: {
            textStyle: {
              color: "#fff",
            },
          },
        },
        yAxis: {
          type: "value",
          axisTick: {
            show: false, //刻度线
          },
          axisLabel: {
            textStyle: {
              color: "#fff",
            },
          },
        },
        grid: {
          left: "2%",
          right: "4%",
          bottom: "2%",
          top: "15%",
          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.number,
            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 getSjhdsqk() {
      try {
        const res = await getSjhdsqk();
        // console.log(res);
        this.data = res.data.list;
        this.data.forEach((item) => {
          this.text.push(item.name);
          this.number.push(item.value);
        });
        this.$nextTick(() => {
          this.gr();
        });
      } catch (error) {
        console.log("数据获取失败");
      }
    },
  },
  mounted() {},
};
</script>
      
  <style scoped lang="scss">
.container6 {
  //   border: 1px solid #00ffff;
  width: 23.6458vw;
  height: 24.6236vh;
  .bar {
    width: 23.6458vw;
    height: 24.6236vh;
  }
}
</style>