fix(图表): 模板中的透视表无法渲染

This commit is contained in:
wisonic 2024-07-29 15:44:08 +08:00
parent 99e990eb5c
commit 3b9666c52f

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)
}
}