eChart折线图动态特效和隔几秒高亮特效

示例:

在这里插入图片描述

说明:

因为现在公司经常要做大屏可视化特效,没办法,只能让图尽量动起来(之前开会挨叼了,说俺们深圳做的,不能比西安那些人做的差。。。)

主要代码:

折线图的滚呀滚特效(ts的,改成js把: anyas any[]两个删了就行了):

let animationChart = (option: any) => {
  // 动画
  let lowLine = [] as any[];
  var zrUtil = echarts.util;

  if (xData.length > 0) {
    // console.log(xData, sData);
    lowLine = [];

    zrUtil.each(xData, function (item, index) {
      lowLine.push([
        {
          coord: [index, sData[index]],
        },
        {
          coord: [index + 1, sData[index + 1]],
        },
      ]);
    });
  }
  if (option.series.length > 1) {
    option.series[1] = {
      name: "出栏总数",
      type: "lines",
      coordinateSystem: "cartesian2d",
      zlevel: 1,
      smooth: true,
      symbol: "circle",
      effect: {
        show: true,
        smooth: true,
        period: 2,
        symbolSize: 8,
      },
      lineStyle: {
        normal: {
          color: "#00E0FF",
          width: 0,
          opacity: 0,
          curveness: 0,
        },
      },
      data: lowLine,
    };
  } else {
    option.series.push({
      name: "出栏总数",
      type: "lines",
      coordinateSystem: "cartesian2d",
      zlevel: 1,
      smooth: true,
      symbol: "circle",
      effect: {
        show: true,
        smooth: true,
        period: 2,
        symbolSize: 8,
      },
      lineStyle: {
        normal: {
          color: "#00E0FF",
          width: 0,
          opacity: 0,
          curveness: 0,
        },
      },
      data: lowLine,
    });
  }
  // 动画结束
};

隔几秒高亮特效:

let changeActiveChart = (option: any) => {
  let app = {
    currentIndex: -1,
  };
  timerChart = setInterval(function () {
    let dataLen = option.series[0].data.length;
    // 取消之前高亮的图形
    myChart.dispatchAction({
      type: "downplay",
      seriesIndex: 0,
      dataIndex: app.currentIndex,
    });
    app.currentIndex = (app.currentIndex + 1) % dataLen;
    // 高亮当前图形
    myChart.dispatchAction({
      type: "highlight",
      seriesIndex: 0,
      dataIndex: app.currentIndex,
    });
    // 显示 tooltip
    myChart.dispatchAction({
      type: "showTip",
      seriesIndex: 0,
      dataIndex: app.currentIndex,
    });
    emit("changeMonth", app.currentIndex);
  }, 1000 * 10);
};

使用:(加在Chart.setOption,生成折线图前)

  if (!myChart) {
    myChart = echarts.init(echartsRef.value);
  }
  let option = getOptions();
  animationChart(option);
  myChart.setOption(option);
  changeActiveChart(option);
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值