原本的默认样式长这样:
也就是有几个图例,就显示几个再加上数字。
默认代码是这样的:
1 2 3 4 5 6 7 8 | tooltip: { trigger: 'axis' , axisPointer: { // 坐标轴指示器,坐标轴触发有效 type: 'cross' , // 默认为直线,可选为:'line' | 'shadow' 'cross' }, confine: true , // 限制tooltip在图标区域内显示 }, |
但我需要的是这样的:
代码如下:
需要加一个formatter函数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | tooltip: { trigger: 'axis' , axisPointer: { // 坐标轴指示器,坐标轴触发有效 type: 'cross' , // 默认为直线,可选为:'line' | 'shadow' 'cross' }, confine: true , //限制tooltip在图表区域内显示 formatter: function (params) { console.log(params); let content = '<div style="text-align: left;width:250px;margin-left:20px">' ; // 创建一个中心对齐的容器 content += '' ; content += '' ; // 显示时间戳 content += '' ; content += '' ; content += '' ; for ( let i = 0; i '; content += ' '; // 格式化为百分比 if (seriesName === "CPU占用率") { content += ' '; // 格式化为百分比 content += ' '; } else if (seriesName === "sys占用率") { content += ' '; content += ' '; } else if (seriesName === "用户占用率") { content += ' '; content += ' '; } } content += ' <table style= "border-bottom:1px solid #COCOCO" ><tbody><tr> <td>${params[0].name?.split( ' ' )[1][1]}</td><td style= "text-indent:5px" >平均</td><td style= "text-indent:5px" >峰值</td><td style= "text-indent:5px" >最高</td> </tr><tr><td style= "text-indent:5px" >${seriesName}</td><td style= "text-indent:5px" >${value.toFixed(2)}</td><td style= "text-indent:5px" >${dataRow.cpu_total_grad_list[param.dataIndex]}</td><td style= "text-indent:5px" >${dataRow.cpu_total_max_list[param.dataIndex]}</td><td style= "text-indent:5px" >${dataRow.cpu_sys_grad_list[param.dataIndex]}</td><td style= "text-indent:5px" >${dataRow.cpu_sys_max_list[param.dataIndex]}</td><td style= "text-indent:5px" >${dataRow.cpu_user_grad_list[param.dataIndex]}</td><td style= "text-indent:5px" >${dataRow.cpu_user_max_list[param.dataIndex]}</td></tr></tbody></table> '; content += ' 最大值所在主机 ${dataRow.cpu_max_host[params[0]?.dataIndex]}'; return content; } }</div> <p><strong>总结 </strong></p> <p>到此这篇关于echarts自定义tooltip中内容的文章就介绍到这了,更多相关echarts自定义tooltip内容内容请搜索IT俱乐部以前的文章或继续浏览下面的相关文章希望大家以后多多支持IT俱乐部!</p> |
相关文章
-
javascript和HTML5利用canvas构建猜牌游戏实现算法
让我猜猜你心中的牌,先随机生成27张牌,不能重复列出三列牌,然后记住其中一张,然后点击牌所在的列,多次就可以猜出你想的牌,具体实现如下,感兴趣的朋友可以参考下哈2013-07-07
最新评论