<template>
  <div>
    <dv-border-box-13>
      <div class="dvrow">
        <div>
          <span class="title-span">近5年开发模具数量</span>
        </div>
      </div>
      <div class="echarts4" id="main2"></div>
    </dv-border-box-13>
  </div>

</template>

<script>
// import * as echarts from "echarts";
export default {
  props: {},
  data() {
    return {};
  },
  created() {},
  mounted() {
    this.echarts4();
  },
  methods: {
    echarts4() {
      var myChart = echarts4.init(document.getElementById("main2"));
      let dataX = [
        "Y2019",
        "Y2020",
        "Y2021",
        "Y2022",
        "Y2023",    
      ];
      // dataX对应的数据
      let data = [44, 55, 66, 46, 67, 69 , 55, 66, 46, 67,];

      var option = {
        dataZoom: [
          {
            // 第一个 dataZoom 组件
            type: "inside",
            xAxisIndex: 0, // 表示这个 dataZoom 组件控制 第一个 xAxis
            startValue: 0, // 数据窗口范围的起始数值index
            endValue: 4, // 数据窗口范围的结束数值index
          },
        ],
        // 这是用于显示提示信息的配置项，通常包括悬浮在图表上时的信息提示。
        tooltip: {
          //提示框组件
          trigger: "axis",
          formatter: "{b}<br />{a0}: {c0}",
          axisPointer: {
            type: "shadow",
            label: {
              backgroundColor: "#6a7985",
            },
          },
          textStyle: {
            color: "#000",
            fontStyle: "normal",
            fontFamily: " LCD2Bold-Bold",
            fontSize: 12,
          },
        },
        grid: {
          left: "5%",
          right: "0%",
          bottom: "10%",
          top: "10%",
          containLabel: true,
        },
        xAxis: [
          {
            type: "category",
            data: dataX,
            axisLabel: {
              //坐标轴刻度标签的相关设置。
              textStyle: {
                color: "white",
                fontStyle: "normal",
                fontSize: 14,
                fontWeight: 700,
              },
              rotate: 0, // 文字倾斜显示
            },
            axisTick: {
              //坐标轴刻度相关设置。
              show: false,
            },
            axisLine: {
              //坐标轴轴线相关设置
              lineStyle: {
                color: "white",
                opacity: 0.4,
              },
            },
            splitLine: {
              //坐标轴在 grid 区域中的分隔线。
              show: false,
            },
          },
        ],
        yAxis: [
          {
            type: "value",
            splitNumber: 4,
            min: 30,
            max: 70,
            interval: 10,
            axisLabel: {
              textStyle: {
                color: "white",
                fontStyle: "normal",
                fontSize: 14,
              },
            },

            axisTick: {
              show: false,
            },
            axisLine: {
              show: true,
            },
            // 背景刻度线
            splitLine: {
              show: true,
              lineStyle: {
                type: "dashed", //solid实线;dashed虚线
                color: "rgb(81, 82, 8,0.5)",
              },
            },
          },
        ],
        // 鼠标放上去提示
        series: [
          {
            name: "办件数",
            type: "bar",
            data: data,
            // 设置每条柱状宽度
            barWidth: 15,
            // label: {
            //   //图形上的文本标签
            //   normal: {
            //     show: true,
            //     position: "top",
            //     textStyle: {
            //       color: "#29F1FA",
            //       fontStyle: "normal",
            //       fontFamily: "微软雅黑",
            //       fontSize: 18,
            //     },
            //   },
            // },

            // 每条数据渐变颜色
            itemStyle: {
              normal: {
                show: true,
                color: new echarts4.graphic.LinearGradient(0, 0, 0, 1, [
                  {
                    offset: 0,
                    color: "#3AE2DB",
                  },
                  {
                    offset: 1,
                    color: "#1DA1F2",
                  },
                ]),

                barBorderRadius: 50,
                borderWidth: 0,
              },
            },
          },
        ],
      };
      option && myChart.setOption(option);
      // 设置定时器, 每隔2s判断是否滚动到末尾, 是则重置为初始状态, 否则向前滚动一位
      this.timerId = setInterval(() => {
        if (option.dataZoom[0].endValue == dataX.length - 1) {
          option.dataZoom[0].endValue = 6;
          option.dataZoom[0].startValue = 0;
        } else {
          option.dataZoom[0].endValue = option.dataZoom[0].endValue + 1;
          option.dataZoom[0].startValue = option.dataZoom[0].startValue + 1;
        }
        myChart.setOption(option);
      }, 2000);
    },
  },
  //组件
  components: {},
};
</script>

<style scoped lang="scss">
.dv-border-box-13 {
  width: 100%;
  height: 180px;
  padding-top: 20px;
  .dvrow {
    height: 15px;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
  }
  .echarts {
    width: 100%;
    height: 140px;
  }
}
</style>
