echarts可视化的那些事

本文档讨论了一个关于Echarts图形配置的问题,即在轮播过程中提示框出现闪烁现象。问题根源被定位为UI提示框添加背景图导致的。文中提供了一段Vue.js代码示例,并展示了如何初始化Echarts图表、配置tooltip以及使用dispatchAction进行提示框操作。尽管找到了问题原因,但目前尚未找到有效解决闪烁的方案。此外,还强调了在需要轮播提示框时正确配置tooltip的重要性。
摘要由CSDN通过智能技术生成

以下存在一个问题:轮播过程会闪一下,目前定位到是变态UI让提示框加背景图造成的,暂时还没有好的解决方式(vue写法)

const data = [820, 932, 901, 934, 1290, 1330, 1320];
      let lineDom = document.getElementById("myLine");
      let myLine = this.$echarts.init(lineDom);
      let option;
      option = {
        xAxis: {
          type: "category",
          splitLine: {
            //是否需要开启分割线
            show: false
          },
          axisTick: {
            //是否需要开启刻度
            show: false
          },
          axisLine: {
            //轴线样式设置
            show: true, //是否显示坐标轴线
            lineStyle: {
              color: "#333"
            }
          },
          axisLabel: {
            //横坐标样式设置
            textStyle: {
              fontSize: 16,
              fontWeight: "bold",
              color: "blue",
              fontFamily: "normal"
            }
          },
          data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
        },
        yAxis: {
          type: "value",
          splitLine: {
            //是否开启分割线
            show: true,
            lineStyle: {
              color: ["pink"],
              width: 2,
              type: "dotted"
            }
          },
          axisTick: {
            //是否开启刻度线
            show: false
          },
          axisLine: {
            //是否显示坐标轴线
            show: true,
            lineStyle: {
              color: "blue"
            }
          },
          axisLabel: {
            interval: 0,
            formatter: `{value}`,
            textStyle: {
              fontSize: 16,
              fontWeight: "normal",
              color: "red",
              fontFamily: "normal"
            }
          }
        },
        tooltip: {
          //提示框样式及内容设置
          type: "axis",
          axisPointer: {
            animation: true,
            animationDuration: 1000
          },
          formatter(params) {
            return `<div style="background:url(${require("../assets/logo.png")}) no-repeat center center;padding:10px">PH:&nbsp&nbsp${
              params.data
            }</br>${params.name}</div>`;
          },
          padding: 0,
          borderWidth: 0,
          borderColor: "red",
          textStyle: {
            fontSize: 16,
            fontWeight: "bold",
            color: "blue",
            fontFamily: "siyuan",
            align: "left"
          }
        },
        legend: {
          show: true,
          top: "5%",
          left: "center",
          textStyle: {
            fontSize: 16,
            fontWeight: "normal",
            color: "pink",
            fontFamily: "normal"
          }
        },
        series: [
          {
            data: data,
            type: "line",
            areaStyle: {}
          }
        ]
      };
      option && myLine.setOption(option);
      let index = 0; //播放所在下标
      let mTime;
      let openTime = function() {
        mTime = setInterval(function() {
          myLine.dispatchAction({
            type: "showTip",
            seriesIndex: 0,
            dataIndex: index
          });
          index++;
          if (index > data.length) {
            index = 0;
          }
          return () => {
            mTime.clearInterval();
          };
        }, 2000);
      };
      //如果没增加移入移出清除,会出现提示框轮播会闪的情况
      lineDom.onmouseover = () => {
        clearInterval(mTime);
      };
      lineDom.onmouseout = () => {
        openTime();
      };
      //window.onload = function() {//页面加载完运行
        //clearInterval(mTime);
        //openTime();
      //};
      openTime();

这块需要注意:如果需要轮播展示提示框,那么option中需要配置tooltip,不会这还有人不知道吧~啊~

主要用到echarts上提供的dispatchAction,点击查看

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值