From 22cbcb4a9257cc8b181716797067a73ff01a6363 Mon Sep 17 00:00:00 2001 From: lSun <15893999301@qq.com> Date: Wed, 31 Jul 2024 09:59:28 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E9=AA=8C=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/static/js/home/home.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/resources/static/js/home/home.js b/src/main/resources/static/js/home/home.js index b9a4899..dbc4254 100644 --- a/src/main/resources/static/js/home/home.js +++ b/src/main/resources/static/js/home/home.js @@ -204,9 +204,10 @@ function echartsone(type){ tooltip: { // 修改tooltip的触发方式,例如改为'axis'轴触发 trigger: 'axis', + confine: true, // 自定义内容格式化函数 // 其他tooltip样式和行为 - extraCssText: 'width:160px;height:100px;', + extraCssText: 'height:100px;', backgroundColor: 'rgba(50,50,50,0.7)', // 背景颜色 borderColor: '#333', // 边框颜色 borderWidth: 1, // 边框宽度 @@ -214,6 +215,7 @@ function echartsone(type){ textStyle: { color: '#fff' // 文本颜色 }, + }, xAxis: { type: 'category', @@ -257,7 +259,7 @@ function echartstwo(){ option = { tooltip: { trigger: 'item', - extraCssText: 'width:200px;height:100px;', + extraCssText: 'width:210px;height:100px;', formatter: function (params) { if (!params || !params.name || !params.value) { return ''; // 如果数据无效,则返回空字符串 @@ -269,8 +271,8 @@ function echartstwo(){ let name = params.name; let value = params.value; - // 每行最多显示15个字符 - const maxCharsPerLine = 8; + // 每行最多显示13个字符 + const maxCharsPerLine = 15; // 将名称分隔成多行 let lines = []; @@ -285,12 +287,16 @@ function echartstwo(){ lines.push(name); // 将每一行添加到最终文本中,并在每行之间添加换行符 - lines.forEach(function (line) { - text += line + '
'; + lines.forEach(function (line,index) { + if (index === lines.length - 1) { + text += line + ':'+ '
'; + } else { + text += line + '
'; + } }); // 添加值 - text += ': ' + value; + text += value; // 返回格式化的文本 return text;