vue 折线图动态向右移动

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, // 初始显示index0-30的数据,可根据你的数据量设置
            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", //背景线为虚线
                color: "rgba(172, 175, 173, .1)", //左侧显示线
              },
            },
            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: {
              //折线图覆盖面积
              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)",
                },
              ]), //渐变色
            },
          },
        ],
      };
      var startNumber = 0;
      var xAxisDatalen = that.lineChartData.data.length;
      var len = 7; //这里请注意
      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);
    },

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值