diff --git a/nezha-fronted/src/components/chart/chart/legend.vue b/nezha-fronted/src/components/chart/chart/legend.vue
index 2824ccf0b..cfb4dff47 100644
--- a/nezha-fronted/src/components/chart/chart/legend.vue
+++ b/nezha-fronted/src/components/chart/chart/legend.vue
@@ -16,7 +16,7 @@
{{item.alias ? item.alias : item.name}}
- {{statistics.value}}
+ {{(keepTwoDecimalFull(statistics.value))}}
@@ -194,6 +194,25 @@ export default {
})
}
},
+ // 四舍五入保留2位小数(不够位数,则用0替补)
+ keepTwoDecimalFull (num) {
+ let result = parseFloat(num)
+ if (isNaN(result)) {
+ return '--'
+ }
+ // result = Math.round(num * 100) / 100
+ // let decimal = result.toString()
+ // let posDecimal = decimal.indexOf('.')
+ // if (posDecimal < 0) {
+ // posDecimal = decimal.length
+ // decimal += '.'
+ // }
+ // while (decimal.length <= posDecimal + 2) {
+ // decimal += '0'
+ // }
+ result = chartDataFormat.getUnit(this.chartInfo.unit ? this.chartInfo.unit : 2).compute(result, null, -1, 2)
+ return result
+ },
getMaxValue (dataArg, chartInfo) {
let maxValue = 0
let minValue = 0
diff --git a/nezha-fronted/src/components/charts/chartDataFormat.js b/nezha-fronted/src/components/charts/chartDataFormat.js
index 691d58d20..b0cc702d2 100644
--- a/nezha-fronted/src/components/charts/chartDataFormat.js
+++ b/nezha-fronted/src/components/charts/chartDataFormat.js
@@ -18,11 +18,11 @@ function short (value, index, type = 1, dot) {
}
}
function percent01 (value, index) {
- value = parseFloat((Number(value)).toPrecision(12))
+ value = parseFloat((Number(value)).toFixed(2))
return `${value} %`
}
function percent02 (value, index) {
- value = parseFloat((Number(value) * 100).toPrecision(12))
+ value = parseFloat((Number(value) * 100).toFixed(2))
return `${value} %`
}
function localFormat (value, index) {
diff --git a/nezha-fronted/src/components/common/js/tools.js b/nezha-fronted/src/components/common/js/tools.js
index f88c3beda..3c29f5d01 100644
--- a/nezha-fronted/src/components/common/js/tools.js
+++ b/nezha-fronted/src/components/common/js/tools.js
@@ -811,7 +811,7 @@ export function getMetricTypeValue (queryItem, type) {
const max = copy.sort((x, y) => { return parseFloat(y[1]) - parseFloat(x[1]) })[0][1]
return max
}
- case 'avg': {
+ case 'average': {
copy = copy.map(t => parseFloat(t[1]))
const sum = eval(copy.join('+'))
const avg = sum / copy.length