echarts自定义tooltip位置和内容

tooltip: {
          trigger: 'item',
          backgroundColor: 'none',
          position: function (pos, params, dom, rect, size) {
            //我这个是每次显示30条数据 所以这么判断
            var obj = params.dataIndex < 15 ? "right" : "left"
            return obj;
          },
          formatter: (params) => {
            //收入和支出是不同颜色 背景 还带个箭头
            var str = this.activeNum == 0 ? '收入' : '支出',
              bg = this.activeNum == 0 ? '#E2F8EE' : '#FFE0C9',
              textColor = this.activeNum == 0 ? '#00A862' : '#F29C00',
              //两个箭头 小于15的显示左边的 大于的显示右边的
              //这个字符串拼接感觉好麻烦
              showLeft = params.dataIndex < 15 ? "block" : "none",
              showRight = params.dataIndex < 15 ? "none" : "block"
            return '<div style="display:flex;align-items:center;justify-content:space-between;color:' + textColor + '"><div style="display:' + showLeft + '"><b style="content:\'\';display: inline-block;height: 0.08rem;width: 0.08rem;border-top: 0.08rem solid transparent; border-bottom: 0.1rem solid transparent;border-right: 0.1rem solid ' + bg + ';"></b></div><div style="flex:1;border-radius:0.05rem;padding: 0.02rem 0.09rem;background:' + bg + '"><p>' + params.name.split('-')[0] + '月' + params.name.split('-')[1] + '日' + str + '</p><p>' + params.value + '元</p></div><div style="display:' + showRight + '"><b style="content:\'\';display: inline-block;height: 0.08rem;width: 0.08rem;border-top: 0.08rem solid transparent; border-bottom: 0.1rem solid transparent;border-left: 0.1rem solid ' + bg + ';"></b></div></div>';
          }
        },

效果图:

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值