6月-echarts使用及踩坑指南

echarts legend头部有遮挡、上半部分显示不全,像被截取了一块

在这里插入图片描述

  • 解决方案
legend-textStyle中加入lineHeight即可
  • 效果
    在这里插入图片描述

echarts多条折现配置双Y轴

在这里插入图片描述

  • 解决方案
// yAxis配置两条数据
 yAxis: [
          {
            type: 'value',
            axisLabel: {
              formatter: '{value}'
            },
          },
          {
            type: 'value',
            axisLabel: {
              formatter: '{value}'
            },
          }
     ]
     //在想要设置为另一条Y轴数据中设置 yAxisIndex 这里注意:0为第一轴;1为第二轴
series: [
    {
      name: "1",
      data: [],
      type: "line",
      lineStyle: {
        color: "#4F9AFF",
      },
      yAxisIndex: 1,
    },
    {
      data: [],
      name: "2",
      type: "bar",
      barWidth: "10px",
    },
    {
      data: [],
      name: "3",
      type: "bar",
      barWidth: "10px",
    },
  ],

柱状图/折线图实现自动滚动、鼠标悬停时停止滚动并获取数据、鼠标离开时继续滚动

   let currentIndex = 0; //高亮index
   const len = res.data.length;//数据长度
 // 鼠标悬浮,停止轮播
      this.overViewChart.on("mouseover", function (params) {
        that.clearTime(); //清除定时器
        that.overViewChart.dispatchAction({
          type: "downplay",
          seriesIndex: currentIndex,
        });
        that.overViewChart.dispatchAction({
          type: "highlight",
          seriesIndex: 0,
          dataIndex: params.dataIndex,
        });
        that.overViewChart.dispatchAction({
          type: "showTip",
          seriesIndex: 0,
          dataIndex: params.dataIndex,
        });
        currentIndex = params.dataIndex;
        that.initTwoBarChart(params.data.key);//获取数据后执行的操作
      });
      // 鼠标离开,继续轮播
      this.overViewChart.on("mouseout", function () {
        that.clearTime();
        that.timer = setInterval(() => {
          // 取消之前高亮的图形
          that.overViewChart.dispatchAction({
            type: "downplay",
            seriesIndex: len,
            dataIndex: currentIndex,
          });
          if (currentIndex >= len - 1) {
            currentIndex = 0;
          } else {
            currentIndex++;
          }
          // 执行高亮
          that.overViewChart.dispatchAction({
            type: "highlight",
            seriesIndex: 0,
            dataIndex: currentIndex,
          });
          // 执行
          that.overViewChart.dispatchAction({
            type: "showTip",
            seriesIndex: 0,
            dataIndex: currentIndex,
          });
          that.initTwoBarChart(resOnline.data[currentIndex].dateString);//轮播时执行的操作
        }, 3000);
         that.timerList.push(that.timer);//由于定时器会反复覆盖,会有清理不干净的情况,所以定时器加入数组、统一清除
      });

  //定时器清理
   clearTime() {
      if (this.timerList.length > 0) {
        this.timerList.forEach((item, index) => {
          clearInterval(item);
        });
        this.timerList = [];
      }
    },

相关推荐

  1. ffmpeg的部署简单使用方式

    2024-06-07 14:30:05       9 阅读
  2. bat指令记录

    2024-06-07 14:30:05       9 阅读
  3. WSL+Ununtu+Docker指南

    2024-06-07 14:30:05       17 阅读
  4. Vue 3 的 setup 函数使用指南

    2024-06-07 14:30:05       6 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-07 14:30:05       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-07 14:30:05       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-07 14:30:05       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-07 14:30:05       20 阅读

热门阅读

  1. LeetCode //C - 168. Excel Sheet Column Title

    2024-06-07 14:30:05       10 阅读
  2. 解决Vscode Copilot连不上网问题

    2024-06-07 14:30:05       9 阅读
  3. 微信小程序计算器

    2024-06-07 14:30:05       10 阅读
  4. 微信小程序上线后获取定位失效

    2024-06-07 14:30:05       11 阅读
  5. 用ffmpeg对视频添加语音、背景音乐和字幕的方法

    2024-06-07 14:30:05       11 阅读
  6. Unity3D DOTS JobSystem物理引擎的使用详解

    2024-06-07 14:30:05       9 阅读
  7. Linux systemctl:掌握软件启动和关闭的利器

    2024-06-07 14:30:05       9 阅读