From d69cd76d090ecf2b050e48e83c8a0e6f900acb81 Mon Sep 17 00:00:00 2001 From: AgAngle <1323481023@qq.com> Date: Fri, 17 Nov 2023 13:47:09 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E6=8A=A5=E5=91=8A=EF=BC=8C?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E7=94=A8=E4=BE=8B=E7=BB=93=E6=9E=9C=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=EF=BC=8C=E7=BB=9F=E8=AE=A1=E7=BB=93=E6=9E=9C=E4=B8=BA?= =?UTF-8?q?=E8=B4=9F=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1032979 --user=陈建星 【测试跟踪】测试计划-报告统计-功能用例统计分析-比例显示负数 https://www.tapd.cn/55049933/s/1437550 --- .../src/components/MsDoughnutPieChart.vue | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/framework/sdk-parent/frontend/src/components/MsDoughnutPieChart.vue b/framework/sdk-parent/frontend/src/components/MsDoughnutPieChart.vue index f8a9f708f6..aa13a1c18e 100644 --- a/framework/sdk-parent/frontend/src/components/MsDoughnutPieChart.vue +++ b/framework/sdk-parent/frontend/src/components/MsDoughnutPieChart.vue @@ -106,16 +106,10 @@ export default { } let dataPercentObj = {}; - let percentCount = 0; for (let i = 0; i < data.length; i++) { let dataName = data[i].name; let value = data[i].value; - let percent = 100 - percentCount; - if (i !== data.length - 1) { - percent = new Number(((value / total) * 100).toFixed(0)); - percentCount += percent; - } - dataPercentObj[dataName] = percent; + dataPercentObj[dataName] = new Number(((value / total) * 100).toFixed(2)); } this.options.legend.formatter = (name) => { let target = 0; @@ -124,13 +118,26 @@ export default { target = data[i].value; } } - return name + " | " + target + " " + dataPercentObj[name] + "%"; + + return name + " | " + target + " " + this.formatNumber( dataPercentObj[name], 2) + "%"; }; this.options.series[0].label.formatter = (params) => { return title + "\n" + count; }; }, + formatNumber(num, decimalPlaces) { + let fixedNum = num.toFixed(decimalPlaces); // 先使用 toFixed 获取指定小数位数的字符串 + let parts = fixedNum.split("."); // 将整数部分和小数部分分开 + + // 如果小数部分存在,且小数部分的长度小于指定的小数位数,则补齐0 + if (parts.length > 1 && parts[1].length < decimalPlaces) { + parts[1] = parts[1].padEnd(decimalPlaces, "0"); + } + + // 将整数部分和小数部分重新拼接起来 + return parts.join("."); + } }, };