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) { switch (aggregation) {
case 'SUM': { case 'SUM': {
return data.reduce((p, n) => { return data.reduce((p, n) => {
return p + n[query[EXTRA_FIELD]] return p + parseFloat(n[query[EXTRA_FIELD]])
}, 0) }, 0)
} }
case 'AVG': { case 'AVG': {
const sum = data.reduce((p, n) => { const sum = data.reduce((p, n) => {
return p + n[query[EXTRA_FIELD]] return p + parseFloat(n[query[EXTRA_FIELD]])
}, 0) }, 0)
return sum / data.length return sum / data.length
} }
case 'MIN': { case 'MIN': {
const result = minBy(data, n => { const result = minBy(data, n => {
return n[query[EXTRA_FIELD]] return parseFloat(n[query[EXTRA_FIELD]])
}) })
return result?.[query[EXTRA_FIELD]] return result?.[query[EXTRA_FIELD]]
} }
case 'MAX': { case 'MAX': {
const result = maxBy(data, n => { const result = maxBy(data, n => {
return n[query[EXTRA_FIELD]] return parseFloat(n[query[EXTRA_FIELD]])
}) })
return result?.[query[EXTRA_FIELD]] return result?.[query[EXTRA_FIELD]]
} }
default: { default: {
return data.reduce((p, n) => { return data.reduce((p, n) => {
return p + n[query[EXTRA_FIELD]] return p + parseFloat(n[query[EXTRA_FIELD]])
}, 0) }, 0)
} }
} }

View File

@ -598,7 +598,7 @@ export function mappingColor(value, defaultColor, field, type) {
} }
export function handleTableEmptyStrategy(chart: Chart) { 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 = [] let intersectionArr = []
const senior = parseJson(chart.senior) const senior = parseJson(chart.senior)
let emptyDataStrategy = senior?.functionCfg?.emptyDataStrategy let emptyDataStrategy = senior?.functionCfg?.emptyDataStrategy