echarts 曲线光点指引

echarts 实现曲线图,并在曲线上添加光标从开始到结束位置循环移动, 如下图

echarts本身有lines的effect可以实现光点移动的效果,但是只能是折线点,不能实现曲线光点移动效果;

实现思路: 画两条一样的曲线,一条是实际展示的曲线,另一条是移动的,根据渐变色实现,开始和结尾都设置为透明色,而中间很短的一部分设置为光点色,然后不断修改光标的位置,这样就形成了一条不断移动的光点;

配置如下:


    let i = 1;
    let step = 0.03;

    let data = [
      [502.84, 205.97, 332.79, 281.55, 398.35, 214.02],
      [1502.84, 1205.97, 1332.79, 1281.55, 1398.35, 1214.02]
    ];
     let a = [ {
            name: "注册总量",
            type: "line",
            smooth: 0.27,
             lineStyle: {
              width: 4
             },
            data: [502.84, 205.97, 332.79, 281.55, 398.35, 214.02],
            animation: false
          },
          {
            name: "注册总量",
            type: "line",
             lineStyle: {
              width: 4
             },
            smooth: 0.27,
            data: [1502.84, 1205.97, 1332.79, 1281.55, 1398.35, 1214.02],
            animation: false
          }]
      let dataIndex = 0;
    setInterval(() => {
      i++;
      let startPre = step * (i-1);
      let start = step * i;
      let end = start + step;
      let endSuffix = end + step;
      if (endSuffix >= 1) {
        endSuffix = 1;
        i = 0;
      }
      // console.log(startPre, start, end, endSuffix);
      let lines = {
        name: "注册总量",
        type: "line",
        smooth: 0.27,
        data: data[dataIndex],
        animation: false,
        lineStyle: {
          width: 4,
          color: {
            type: "linear",
            colorStops: [
              {
                offset: startPre,
                color: "transparent"
              },
              {
                offset: start,
                color: "red"
              },
              {
                offset: end,
                color: "red"
              },
              {
                offset: endSuffix,
                color: "transparent"
              }
            ]
          }
        }
      };
      a[2] = (lines)
      if (endSuffix >= 1) {
        dataIndex++;
        if (dataIndex >= data.length) {
          dataIndex = 0;
        }
      }
      option = {
        xAxis: {
          type: "category",
          data: ["A", "B", "C", "D", "E", "F"]
        },
        yAxis: {
          type: "value"
        },
        series: a
      };

      myChart.setOption(option);
    }, 100);

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值