echarts 提示框设置自定义样式

echarts中遇到的需要自定义的提示框样式,大致样式是这样,我们需要使用echarts中的属性和自定义的html元素共同实现
带颜色的方块在formatter的函数里边使用自定义html实现,提示框样式在属性中实现
请添加图片描述

  • 上代码:
tooltip: {
	borderWidth: 1, //边框宽度设置1
	padding: 16,
	backgroundColor: '#041E4FFF', //背景颜色,比自定义的html元素优先级高
	axisPointer: {
		type: 'shadow',
		crossStyle: {
			color: '#fff'
		}
	},
	extraCssText: 'box-shadow: 0 0 0.1rem rgba(0,120,234,0.8)', //提示框阴影样式
	textStyle: { //展示的文字的样式,优先级比自定义的html元素高
		color: '#fff',
		fontSize: '20',
		fontFamily: 'SourceHanSansCN-Normal'
	},
	formatter: function (params) {
		if (params.data.showName && params.data.showName.length > 0) {
		//这个位置可以根据自己的需求自定义html元素样式
			return '<div width:2rem;height:1rem;color:#fff !important;font-size:0.08rem;padding: 0 !important; border:0.005rem solid #0856AF !important;" > ' + `<span style="color:#29A0F4FF;line-height:0.15rem">${params.data.name}</span>` + '<br><div style="margin-top:0.01rem ;margin-bottom:-0.04rem"><span 0 style="display: inline-block;margin-left: 0.08rem ; margin-right: 0.03rem; border-radius: 0; width: 8px; height: 8px;background-color: #0ADE0FFF;"></span>正常设备数:' + params.data.showName[0].normal + '</div><br><div style="margin-top:0.01rem;margin-bottom:-0.04rem"><span  style="display: inline-block;margin-left: 0.08rem; ; margin-right: 0.03rem; border-radius: 0; width: 8px; height: 8px;background-color: #EA162FFF;"></span>异常设备数:' + params.data.showName[0].error + '</div><br><span  style="display: inline-block;margin-left: 0.08rem; ; margin-right: 0.03rem; border-radius: 0; width: 8px; height: 8px;background-color: #C9C9C9FF;"></span>离线设备数:' + params.data.showName[0].offline + '<br><br><span style="color:#29A0F4FF;line-height:0.15rem">基本信息:</span><br>' + '<div style="margin-top:0.03rem"><span style="margin-left: 0.08rem;">位置:</span>' + params.data.showName[1] + '</div></div>';
		} else {
			return params.data.name + '<br>无相关数据';
		}
	}
},
  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值