echarts 鼠标移入部分数据不显示tooltip提示内容

思路:

(1)鼠标移入部分数据列,不显示tooltip提示,我们可以在tooltip的formatter属性里面加if条件判断,不符合条件的数据列return空字符串就行。

(2)但这个方法会破坏原有的tooltip样式,我们要需要自己重新定义属性的css样式。

 代码实现:

tooltip: {
     trigger: 'axis',
     formatter:(params)=>{
        let res = `<h3 style="font-size:14px;line-height:14px;font-weight:400;color:#666666;">${params[0].name}</h3>`
        for ( let item of params ) {
            if ( item.name !== "" ) {
               res += `<h3 style="font-size:14px;line-height:14px;margin-top:13px;color:#333333;"><span style="width:6px;height:6px;border-radius:2px;background:${item.color};margin-top: -6x;display: inline-block;margin: 3px;"></span>${item.seriesName}&nbsp;&nbsp;&nbsp;${item.data}</h3>`
             } else 
               return '';  //y轴上的第一组数据不显示tooltip
         }
         return res;
     },
     show: true,
     showContent: true,
     backgroundColor: '#fff',
     extraCssText: 'box-shadow:-2px 0px 9px 2px rgba(61,126,255,0.45)',
     padding: 20, // 内边距
     axisPointer: {    //纵向指示线
         type: 'line'
     }
},

 可以在formatter里面将params打印出来,看看不需要展示tooltip的数据列有哪些特质,如我的例子当中,第一组数据的name属性值为空,那么就以此为if条件语句的判断依据,碰到name为空的数据直接return '';

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值