feat(图表): 透视表支持配置指标的总计名称 #14790

* feat(图表): 透视表支持配置指标的总计名称 #14790

* fix(图表): 修复图例配置有两个图标配置
This commit is contained in:
wisonic-s
2025-04-01 15:26:36 +08:00
committed by GitHub
parent b37e918374
commit 582fb57b28
4 changed files with 61 additions and 5 deletions

View File

@@ -629,11 +629,18 @@ declare interface CalcTotals {
*/
declare interface CalcTotalCfg extends Axis {
dataeaseName: string
/**
* 聚合方式
*/
aggregation: 'MIN' | 'MAX' | 'AVG' | 'SUM' | 'CUSTOM' | ''
/**
* 自定义汇总表达式
*/
originName: string
/**
* 别名
*/
label: string
}
/**

View File

@@ -318,13 +318,16 @@ onMounted(() => {
:label="t('chart.show_range_bg')"
/>
</el-form-item>
<div style="flex: 1; display: flex" v-if="state.legendForm.showRange">
<div
style="flex: 1; display: flex"
v-if="showProperty('showRange') && state.legendForm.showRange"
>
<el-form-item :label="t('chart.icon')" class="form-item" :class="'form-item-' + themes">
<el-select
:effect="themes"
v-model="state.legendForm.miscForm.bullet.bar.ranges.symbol"
:placeholder="t('chart.icon')"
@change="changeMisc()"
@change="changeMisc('bullet.bar.ranges.symbol')"
>
<el-option
v-for="item in iconSymbolOptions"
@@ -340,7 +343,7 @@ onMounted(() => {
:effect="themes"
v-model="state.legendForm.miscForm.bullet.bar.ranges.symbolSize"
size="small"
@change="changeMisc()"
@change="changeMisc('bullet.bar.ranges.symbolSize')"
>
<el-option
v-for="option in sizeList"

View File

@@ -160,6 +160,7 @@ const init = () => {
total.dataeaseName = totalCfg[0].dataeaseName
total.aggregation = totalCfg[0].aggregation
total.originName = totalCfg[0].originName
total.label = totalCfg[0].label
}
})
@@ -175,6 +176,7 @@ const changeTotal = (totalItem, totals) => {
if (item.dataeaseName === totalItem.dataeaseName) {
totalItem.aggregation = item.aggregation
totalItem.originName = item.originName
totalItem.label = item.label
return
}
}
@@ -184,6 +186,7 @@ const changeTotalAggr = (totalItem, totals, colOrNum) => {
const item = totals[i]
if (item.dataeaseName === totalItem.dataeaseName) {
item.aggregation = totalItem.aggregation
item.label = totalItem.label
break
}
}
@@ -197,7 +200,8 @@ const setupTotalCfg = (totalCfg, axis) => {
axis.forEach(i => {
totalCfg.push({
dataeaseName: i.dataeaseName,
aggregation: 'SUM'
aggregation: 'SUM',
label: i.chartShowName ?? i.name
})
})
return
@@ -215,7 +219,8 @@ const setupTotalCfg = (totalCfg, axis) => {
totalCfg.push({
dataeaseName: i.dataeaseName,
aggregation: cfgMap[i.dataeaseName] ? cfgMap[i.dataeaseName].aggregation : 'SUM',
originName: cfgMap[i.dataeaseName] ? cfgMap[i.dataeaseName].originName : ''
originName: cfgMap[i.dataeaseName] ? cfgMap[i.dataeaseName].originName : '',
label: cfgMap[i.dataeaseName] ? cfgMap[i.dataeaseName].label : i.chartShowName ?? i.name
})
})
}
@@ -657,6 +662,27 @@ onMounted(() => {
</el-icon>
</el-col>
</el-form-item>
<el-form-item
class="form-item"
:label="t('chart.total_label')"
:class="'form-item-' + themes"
>
<el-input
:effect="themes"
:placeholder="t('chart.total_label')"
size="small"
maxlength="20"
v-model="state.colTotalItem.label"
clearable
@change="
changeTotalAggr(
state.colTotalItem,
state.tableTotalForm.col.calcTotals.cfg,
'col.calcTotals.cfg'
)
"
/>
</el-form-item>
<el-form-item
v-if="chart.type === 'table-pivot'"
:label="t('chart.total_sort')"

View File

@@ -328,6 +328,26 @@ export class TablePivot extends S2ChartView<PivotSheet> {
s2Options.style.hierarchyCollapse = true
}
}
// 列汇总别名
if (
chart.xAxisExt?.length &&
chart.yAxis?.length > 1 &&
tableTotal.col.showGrandTotals &&
tableTotal.col.calcTotals?.cfg?.length
) {
const colTotalCfgMap = tableTotal.col.calcTotals.cfg.reduce((p, n) => {
p[n.dataeaseName] = n
return p
}, {})
s2Options.layoutCoordinate = (_, __, col) => {
if (col?.isGrandTotals) {
if (colTotalCfgMap[col.value]) {
col.label = colTotalCfgMap[col.value].label
// col.value = colTotalCfgMap[col.value].label
}
}
}
}
// tooltip
this.configTooltip(chart, s2Options)
// 开始渲染