六月-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 = [];
      }
    },

echarts tooltip过长出现滚动条及不超出屏幕显示

			tooltip: {
				trigger: "axis",
				backgroundColor: "#54AEEC", //设置背景图片 rgba格式
				color: "#fff",
				height: "50px",
				padding: [15, 15],
				enterable: true,//滚动条
				extraCssText: "max-width:60%;max-height:83%; overflow: auto; ",//滚动条
				textStyle: {
					color: "white", //设置文字颜色
					padding: 10,
					fontSize: 14
				},
				//改变提示框的位置 不超出屏幕显示 
				position: function(point, params, dom, rect, size) {
				//其中point为当前鼠标的位置,
				//size中有两个属性:viewSize和contentSize,分别为外层div和tooltip提示框的大小
				// 鼠标坐标和提示框位置的参考坐标系是:以外层div的左上角那一点为原点,x轴向右,y轴向下
					// 提示框位置
					var x = 0; // x坐标位置
					var y = 0; // y坐标位置
					// 当前鼠标位置
					var pointX = point[0];
					var pointY = point[1];
					// 提示框大小
					var boxWidth = size.contentSize[0];
					var boxHeight = size.contentSize[1];
					// boxWidth > pointX 说明鼠标左边放不下提示框
					if (boxWidth > pointX) {
						x = 5;
					} else {
						// 左边放的下
						x = pointX - boxWidth;
					}
					// boxHeight > pointY 说明鼠标上边放不下提示框
					if (boxHeight > pointY) {
						y = 5;
					} else {
						// 上边放得下
						y = pointY - boxHeight;
					}
					return [x, y];
				}
			},

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值