diff --git a/core/core-backend/src/main/java/io/dataease/chart/charts/impl/table/TablePivotHandler.java b/core/core-backend/src/main/java/io/dataease/chart/charts/impl/table/TablePivotHandler.java index 38e1ddf391..afd07ab49d 100644 --- a/core/core-backend/src/main/java/io/dataease/chart/charts/impl/table/TablePivotHandler.java +++ b/core/core-backend/src/main/java/io/dataease/chart/charts/impl/table/TablePivotHandler.java @@ -74,7 +74,9 @@ public class TablePivotHandler extends GroupChartHandler { var rowAxis = view.getXAxis(); var colAxis = view.getXAxisExt(); var dataMap = new HashMap(); - var quotaIds = view.getYAxis().stream().map(ChartViewFieldDTO::getDataeaseName).collect(Collectors.toSet()); + if (CollectionUtils.isEmpty(rowAxis)) { + return dataMap; + } // 行总计,列维度聚合加上自定义字段 var row = tableTotal.getRow(); if (row.isShowGrandTotals()) { @@ -116,7 +118,7 @@ public class TablePivotHandler extends GroupChartHandler { } // 列总计,行维度聚合加上自定义字段 var col = tableTotal.getCol(); - if (col.isShowGrandTotals()) { + if (col.isShowGrandTotals() && CollectionUtils.isNotEmpty(colAxis)) { var yAxis = getCustomFields(view, col.getCalcTotals().getCfg()); if (!yAxis.isEmpty()) { var result = getData(sqlMeta, rowAxis, yAxis, allFields, crossDs, dsMap, view, provider, needOrder); @@ -129,7 +131,7 @@ public class TablePivotHandler extends GroupChartHandler { } } // 列小计,行维度聚合,自定义指标数 * (列维度的数量 - 1) - if (col.isShowSubTotals()) { + if (col.isShowSubTotals() && colAxis.size() >= 2) { var yAxis = getCustomFields(view, col.getCalcSubTotals().getCfg()); if (!yAxis.isEmpty()) { var tmpData = new ArrayList>(); @@ -173,7 +175,7 @@ public class TablePivotHandler extends GroupChartHandler { } } // 行总计里面的列小计 - if (row.isShowGrandTotals() && col.isShowSubTotals()) { + if (row.isShowGrandTotals() && col.isShowSubTotals() && colAxis.size() >= 2) { var yAxis = getCustomFields(view, col.getCalcTotals().getCfg()); if (!yAxis.isEmpty()) { var tmpData = new ArrayList>(); @@ -194,7 +196,7 @@ public class TablePivotHandler extends GroupChartHandler { } } // 列总计里面的行小计 - if (col.isShowGrandTotals() && row.isShowGrandTotals()) { + if (col.isShowGrandTotals() && row.isShowGrandTotals() && rowAxis.size() >= 2) { var yAxis = getCustomFields(view, row.getCalcTotals().getCfg()); if (!yAxis.isEmpty()) { var tmpData = new ArrayList>(); @@ -215,7 +217,7 @@ public class TablePivotHandler extends GroupChartHandler { } } // 行小计和列小计相交部分 - if (row.isShowSubTotals() && col.isShowSubTotals()) { + if (row.isShowSubTotals() && col.isShowSubTotals() && colAxis.size() >= 2 && rowAxis.size() >= 2) { var yAxis = getCustomFields(view, col.getCalcTotals().getCfg()); if (!yAxis.isEmpty()) { var tmpData = new ArrayList>>(); @@ -250,6 +252,14 @@ public class TablePivotHandler extends GroupChartHandler { private Map buildCustomCalcResult(List data, List dimAxis, List quotaAxis) { var rootResult = new HashMap(); + if (CollectionUtils.isEmpty(dimAxis)) { + var rowData = data.getFirst(); + for (int i = 0; i < rowData.length; i++) { + var qAxis = quotaAxis.get(i); + rootResult.put(qAxis.getDataeaseName(), rowData[i]); + } + return rootResult; + } for (int i = 0; i < data.size(); i++) { var rowData = data.get(i); Map curSubMap = rootResult; diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-pivot.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-pivot.ts index 0f34e137a3..100b84970f 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-pivot.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-pivot.ts @@ -509,7 +509,7 @@ function getCustomCalcResult(query, axisMap, status: TotalStatus, customCalc) { const rowPath = getTreePath(query, row) const colPath = getTreePath(query, col) const path = [...rowPath, ...colPath] - const { data } = colSubTotal[subLevel] + const { data } = colSubTotal?.[subLevel] let val if (path.length && data) { path.push(quotaField) @@ -526,6 +526,11 @@ function getCustomCalcResult(query, axisMap, status: TotalStatus, customCalc) { path.push(quotaField) val = get(rowTotal.data, path) } + // 列维度为空,行维度不为空 + if (!col.length && row.length) { + const path = [query[EXTRA_FIELD]] + val = get(rowTotal.data, path) + } return val } // 行小计 @@ -535,7 +540,7 @@ function getCustomCalcResult(query, axisMap, status: TotalStatus, customCalc) { const colPath = getTreePath(query, col) const rowPath = getTreePath(query, row) const path = [...colPath, ...rowPath] - const { data } = rowSubTotal[rowLevel] + const { data } = rowSubTotal?.[rowLevel] let val if (path.length && rowSubTotal) { path.push(quotaField) @@ -547,7 +552,7 @@ function getCustomCalcResult(query, axisMap, status: TotalStatus, customCalc) { if (status.isRowTotal && status.isColSubTotal) { const { colSubInRowTotal } = customCalc const colLevel = getSubLevel(query, col) - const { data } = colSubInRowTotal[colLevel] + const { data } = colSubInRowTotal?.[colLevel] const colPath = getTreePath(query, col) let val if (colPath.length && colSubInRowTotal) { @@ -560,7 +565,7 @@ function getCustomCalcResult(query, axisMap, status: TotalStatus, customCalc) { if (status.isColTotal && status.isRowSubTotal) { const { rowSubInColTotal } = customCalc const rowSubLevel = getSubLevel(query, row) - const data = rowSubInColTotal[rowSubLevel]?.data + const data = rowSubInColTotal?.[rowSubLevel]?.data const path = getTreePath(query, row) let val if (path.length && rowSubInColTotal) { @@ -574,7 +579,7 @@ function getCustomCalcResult(query, axisMap, status: TotalStatus, customCalc) { const { rowSubInColSub } = customCalc const rowSubLevel = getSubLevel(query, row) const colSubLevel = getSubLevel(query, col) - const { data } = rowSubInColSub[rowSubLevel][colSubLevel] + const { data } = rowSubInColSub?.[rowSubLevel]?.[colSubLevel] const rowPath = getTreePath(query, row) const colPath = getTreePath(query, col) const path = [...rowPath, ...colPath]