Merge pull request #11217 from dataease/pr@dev-v2@fix_table_pivot_template

fix(图表): 模板中的透视表无法渲染
This commit is contained in:
wisonic-s 2024-07-29 15:45:05 +08:00 committed by GitHub
commit 75aff199a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -386,16 +386,16 @@ function customCalcFunc(query, data, totalCfgMap) {
if (!data?.length || !query[EXTRA_FIELD]) {
return 0
}
const aggregation = totalCfgMap[query[EXTRA_FIELD]].aggregation
const aggregation = totalCfgMap[query[EXTRA_FIELD]]?.aggregation || 'SUM'
switch (aggregation) {
case 'SUM': {
return data.reduce((p, n) => {
return p + parseFloat(n[query[EXTRA_FIELD]])
return p + parseFloat(n[query[EXTRA_FIELD]] ?? 0)
}, 0)
}
case 'AVG': {
const sum = data.reduce((p, n) => {
return p + parseFloat(n[query[EXTRA_FIELD]])
return p + parseFloat(n[query[EXTRA_FIELD]] ?? 0)
}, 0)
return sum / data.length
}
@ -413,7 +413,7 @@ function customCalcFunc(query, data, totalCfgMap) {
}
default: {
return data.reduce((p, n) => {
return p + parseFloat(n[query[EXTRA_FIELD]])
return p + parseFloat(n[query[EXTRA_FIELD]] ?? 0)
}, 0)
}
}