fix(视图): 修复透视表计数字段汇总计算错误 #10499

This commit is contained in:
wisonic 2024-07-09 11:27:47 +08:00
parent bdf5292cd6
commit 49c3e012d8
2 changed files with 6 additions and 6 deletions

View File

@ -344,30 +344,30 @@ function customCalcFunc(query, data, totalCfgMap) {
switch (aggregation) {
case 'SUM': {
return data.reduce((p, n) => {
return p + n[query[EXTRA_FIELD]]
return p + parseFloat(n[query[EXTRA_FIELD]])
}, 0)
}
case 'AVG': {
const sum = data.reduce((p, n) => {
return p + n[query[EXTRA_FIELD]]
return p + parseFloat(n[query[EXTRA_FIELD]])
}, 0)
return sum / data.length
}
case 'MIN': {
const result = minBy(data, n => {
return n[query[EXTRA_FIELD]]
return parseFloat(n[query[EXTRA_FIELD]])
})
return result?.[query[EXTRA_FIELD]]
}
case 'MAX': {
const result = maxBy(data, n => {
return n[query[EXTRA_FIELD]]
return parseFloat(n[query[EXTRA_FIELD]])
})
return result?.[query[EXTRA_FIELD]]
}
default: {
return data.reduce((p, n) => {
return p + n[query[EXTRA_FIELD]]
return p + parseFloat(n[query[EXTRA_FIELD]])
}, 0)
}
}

View File

@ -598,7 +598,7 @@ export function mappingColor(value, defaultColor, field, type) {
}
export function handleTableEmptyStrategy(chart: Chart) {
let newData = chart.data?.tableRow as Record<string, any>[]
let newData = (chart.data?.tableRow || []) as Record<string, any>[]
let intersectionArr = []
const senior = parseJson(chart.senior)
let emptyDataStrategy = senior?.functionCfg?.emptyDataStrategy