diff options
| author | zyh <[email protected]> | 2024-08-09 16:14:30 +0800 |
|---|---|---|
| committer | zyh <[email protected]> | 2024-08-09 16:14:30 +0800 |
| commit | 5c49e55d950cadf3094b041c1171da3aec8cfbed (patch) | |
| tree | e0c930a24e625b1b6b8122b33bb247f25cb0a0d6 | |
| parent | 7adbb0123b3b18b4e1f5decdda4adccdac3d2a01 (diff) | |
NEZ-3498 fix: 图表Data组下bits单位转换异常rel-24.01.34
| -rw-r--r-- | nezha-fronted/src/components/chart/chartDataFormat.js | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/nezha-fronted/src/components/chart/chartDataFormat.js b/nezha-fronted/src/components/chart/chartDataFormat.js index f2422a57b..108882685 100644 --- a/nezha-fronted/src/components/chart/chartDataFormat.js +++ b/nezha-fronted/src/components/chart/chartDataFormat.js @@ -530,19 +530,17 @@ function asciiCompute (num, ascii, units, dot = 2, isBits = false) { } num = Number(num) if (isBits) { - num = num / 8 - if (num < 8) { + if (num >= 8) { + num = num / 8 + } else { return num.toFixed(dot) + ' ' + units[0] } - if (num < ascii) { - return num.toFixed(dot) + ' ' + units[1] - } } const SIGN = num > 0 ? 1 : -1 num = Math.abs(num) let carry = 0 if (num > 1) { - let log = Math.log(num) / Math.log(ascii) + const log = Math.log(num) / Math.log(ascii) carry = Math.floor(log) num = num / Math.pow(ascii, carry) } @@ -551,6 +549,9 @@ function asciiCompute (num, ascii, units, dot = 2, isBits = false) { // carry = parseInt(log) // num = num / Math.pow(ascii, carry) // } + if (isBits) { + carry++ + } if (Number.isInteger(num)) { return num * SIGN + ' ' + units[carry] } else { |
