current position:Home>Vue line graph moves dynamically to the right

Vue line graph moves dynamically to the right

2022-04-29 08:50:40囍囍囍囍囍囍囍囍囍囍 A

initData() {
      var that = this;
      if (!that.lineChartData) return;
      this.option = {
        grid: {
          containLabel: true,
          left: 12,
          top: 45,
          right: 40,
          bottom: 0,
        },
        dataZoom: [
          {
            type: "slider",
            show: false,
            realtime: true,
            startValue: 0,
            endValue: 7, //  Initial display index0-30 The data of , It can be set according to the amount of data you have 
            filterMode: "none",
          },
        ],
        xAxis: {
          type: "category",
          axisLine: {
            show: true,
            lineStyle: {
              color: "rgba(172, 175, 173, .6)",
            },
          },
          axisTick: {
            show: false,
          },
          axisLabel: {
            interval: 0,
            textStyle: {
              color: "#fff",
            },
            margin: 15,
          },
          data: that.lineChartData.xData,
        },
        yAxis: [
          {
            type: "value",
            name: that.lineChartData.unit,
            nameTextStyle: {
              color: "#ffffff",
              padding: [2, 30, 2, 0],
            },
            // scale: true,
            splitNumber: 2,
            axisLabel: {
              textStyle: {
                color: "#fff",
              },
              margin: 10,
            },
            axisTick: {
              show: false,
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: "rgba(172, 175, 173, .6)",
              },
            },
            splitLine: {
              show: true,
              lineStyle: {
                type: "dashed", // The background line is a dotted line 
                color: "rgba(172, 175, 173, .1)", // Left display line 
              },
            },
            data: [],
          },
        ],
        series: [
          {
            name: "123",
            type: "line",
            data: that.lineChartData.data,
            barWidth: 6,
            itemStyle: {
              normal: {
                color: "rgba(0, 214, 237, 1)",
                barBorderRadius: [10, 10, 10, 10],
              },
            },
            areaStyle: {
              // Line chart coverage area 
              color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
                {
                  offset: 0,
                  color: "rgba(0, 0, 0, 0)",
                },
                {
                  offset: 1,
                  color: "rgba(0, 214, 237, 0.69)",
                },
              ]), // gradient 
            },
          },
        ],
      };
      var startNumber = 0;
      var xAxisDatalen = that.lineChartData.data.length;
      var len = 7; // Here, please pay attention to 
      timer && clearInterval(timer);
      timer = setInterval(function () {
        if (startNumber === xAxisDatalen - len) {
          startNumber = 0;
        }
        //myChart.dispatchAction({
		    //type: 'dataZoom',
			//startValue: startNumber,
			//endValue: startNumber + len,
		//});
        that.option.dataZoom[0].startValue = startNumber;
        that.option.dataZoom[0].endValue = startNumber + len;
        startNumber++;
        that.refreshChart();
      }, 2000);
    },

copyright notice
author[囍囍囍囍囍囍囍囍囍囍 A],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/119/202204290621251032.html