diff --git a/core/core-backend/src/main/java/io/dataease/chart/manage/ChartDataManage.java b/core/core-backend/src/main/java/io/dataease/chart/manage/ChartDataManage.java index 42a790e9a1..fbc1122432 100644 --- a/core/core-backend/src/main/java/io/dataease/chart/manage/ChartDataManage.java +++ b/core/core-backend/src/main/java/io/dataease/chart/manage/ChartDataManage.java @@ -114,12 +114,26 @@ public class ChartDataManage { List allFields = getAllChartFields(view); ChartViewDTO chartViewDTO = null; - if (StringUtils.equalsIgnoreCase(view.getType(), "chart-mix")) { + if (StringUtils.containsIgnoreCase(view.getType(), "chart-mix")) { + // 需要排除掉除类别轴以外所有的排序 + view.getXAxisExt().forEach(dto -> dto.setSort("none")); + view.getExtBubble().forEach(dto -> dto.setSort("none")); + view.getExtStack().forEach(dto -> dto.setSort("none")); + view.getYAxis().forEach(dto -> dto.setSort("none")); + view.getYAxisExt().forEach(dto -> dto.setSort("none")); + //左轴右轴需要分别调用一次查询 String viewJson = (String) JsonUtil.toJSONString(view); Map data = new HashMap<>(); //针对左轴,删除yAxisExt ChartViewDTO view1 = JsonUtil.parseObject(viewJson, ChartViewDTO.class); + if (!StringUtils.equalsIgnoreCase(view.getType(), "chart-mix-group")) { + view1.setXAxisExt(new ArrayList<>()); + } + if (!StringUtils.equalsIgnoreCase(view.getType(), "chart-mix-stack")) { + view1.setExtStack(new ArrayList<>()); + } + view1.setExtBubble(new ArrayList<>()); view1.setYAxisExt(new ArrayList<>()); if (view1.getSenior() != null) { ChartSeniorAssistCfgDTO assistLineCfg1 = JsonUtil.parseObject((String) JsonUtil.toJSONString(view1.getSenior().get("assistLineCfg")), ChartSeniorAssistCfgDTO.class); @@ -145,13 +159,17 @@ public class ChartDataManage { } } view2.setXAxisExt(view2.getExtBubble()); + view2.setExtStack(new ArrayList<>()); view2.setExtBubble(new ArrayList<>()); ChartViewDTO right = calcData(view2, chartExtRequest, allFields, viewFields); data.put("right", right.getData()); //重新组装 chartViewDTO = BeanUtils.copyBean(new ChartViewDTO(), left); + chartViewDTO.setXAxisExt(view.getXAxisExt()); + chartViewDTO.setExtStack(view.getExtStack()); chartViewDTO.setYAxisExt(view.getYAxisExt()); + chartViewDTO.setExtBubble(view.getExtBubble()); chartViewDTO.setData(data); chartViewDTO.setSenior(view.getSenior()); } else { @@ -171,12 +189,12 @@ public class ChartDataManage { || ("antv".equalsIgnoreCase(view.getRender()) && "line".equalsIgnoreCase(view.getType())) || StringUtils.equalsIgnoreCase(view.getType(), "flow-map") || StringUtils.equalsIgnoreCase(view.getType(), "sankey") - || StringUtils.equalsIgnoreCase(view.getType(), "chart-mix") + || StringUtils.containsIgnoreCase(view.getType(), "chart-mix") ) { xAxis.addAll(xAxisExt); } List yAxis = new ArrayList<>(view.getYAxis()); - if (StringUtils.equalsIgnoreCase(view.getType(), "chart-mix") + if (StringUtils.containsIgnoreCase(view.getType(), "chart-mix") || StringUtils.equalsIgnoreCase(view.getType(), "bidirectional-bar") || StringUtils.equalsIgnoreCase(view.getType(), "quadrant") || StringUtils.containsIgnoreCase(view.getType(), "progress-bar")) { @@ -836,8 +854,15 @@ public class ChartDataManage { } else if (StringUtils.containsIgnoreCase(view.getType(), "bidirectional-bar") || StringUtils.containsIgnoreCase(view.getType(), "progress-bar")) { mapChart = ChartDataBuild.transMixChartDataAntV(xAxisBase, xAxis, new ArrayList<>(), yAxis, view, data, isDrill); - } else if (StringUtils.containsIgnoreCase(view.getType(), "chart-mix")) { + } else if (StringUtils.containsIgnoreCase(view.getType(), "chart-mix") && !StringUtils.containsIgnoreCase(view.getType(), "stack")) { mapChart = ChartDataBuild.transMixChartDataAntV(xAxisBase, xAxis, xAxisExt, yAxis, view, data, isDrill); + } else if (StringUtils.containsIgnoreCase(view.getType(), "chart-mix") && StringUtils.containsIgnoreCase(view.getType(), "stack")) { + if (CollectionUtils.isNotEmpty(extStack)) { + mapChart = ChartDataBuild.transMixChartStackDataAntV(xAxisBase, xAxis, extStack, yAxis, view, data, isDrill); + } else { + //右轴还是走原逻辑 + mapChart = ChartDataBuild.transMixChartDataAntV(xAxisBase, xAxis, xAxisExt, yAxis, view, data, isDrill); + } } else if (StringUtils.containsIgnoreCase(view.getType(), "label")) { mapChart = ChartDataBuild.transLabelChartData(xAxis, yAxis, view, data, isDrill); } else if (StringUtils.containsIgnoreCase(view.getType(), "quadrant")) { @@ -1321,7 +1346,7 @@ public class ChartDataManage { xAxis.addAll(xAxisExt); } List yAxis = new ArrayList<>(view.getYAxis()); - if (StringUtils.equalsIgnoreCase(view.getType(), "chart-mix")) { + if (StringUtils.containsIgnoreCase(view.getType(), "chart-mix")) { List yAxisExt = new ArrayList<>(view.getYAxisExt()); yAxis.addAll(yAxisExt); } diff --git a/core/core-backend/src/main/java/io/dataease/chart/utils/ChartDataBuild.java b/core/core-backend/src/main/java/io/dataease/chart/utils/ChartDataBuild.java index 58ebef4c2c..ee8e78edc4 100644 --- a/core/core-backend/src/main/java/io/dataease/chart/utils/ChartDataBuild.java +++ b/core/core-backend/src/main/java/io/dataease/chart/utils/ChartDataBuild.java @@ -5,6 +5,7 @@ import io.dataease.i18n.Lang; import io.dataease.i18n.Translator; import io.dataease.utils.IDUtils; import io.dataease.utils.JsonUtil; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.ObjectUtils; @@ -172,7 +173,7 @@ public class ChartDataBuild { axisChartDataDTO.setCategory(StringUtils.defaultIfBlank(yAxis.get(j).getChartShowName(), yAxis.get(j).getName())); buildDynamicValue(view, axisChartDataDTO, row, size, extSize); - Map object = JsonUtil.parse((String) JsonUtil.toJSONString(axisChartDataDTO) , HashMap.class); + Map object = JsonUtil.parse((String) JsonUtil.toJSONString(axisChartDataDTO), HashMap.class); object.put("x", new BigDecimal(row[0])); object.put("y", new BigDecimal(row[1])); @@ -515,7 +516,7 @@ public class ChartDataBuild { } // antV组合图形 - public static Map transMixChartDataAntV(List xAxisBase, List xAxis,List xAxisExt, List yAxis, ChartViewDTO view, List data, boolean isDrill) { + public static Map transMixChartDataAntV(List xAxisBase, List xAxis, List xAxisExt, List yAxis, ChartViewDTO view, List data, boolean isDrill) { Map map = new HashMap<>(); List series = new ArrayList<>(); @@ -583,7 +584,7 @@ public class ChartDataBuild { } axisChartDataDTO.setCategory( StringUtils.defaultIfBlank(b.toString(), - StringUtils.defaultIfBlank(yAxis.get(j).getChartShowName(), yAxis.get(j).getName()))); + StringUtils.defaultIfBlank(yAxis.get(j).getChartShowName(), yAxis.get(j).getName()))); buildDynamicValue(view, axisChartDataDTO, d, size, extSize); series.get(j).getData().add(axisChartDataDTO); } @@ -593,6 +594,90 @@ public class ChartDataBuild { return map; } + public static Map transMixChartStackDataAntV(List xAxisBase, List xAxis, List extStack, List yAxis, ChartViewDTO view, List data, boolean isDrill) { + + if (CollectionUtils.isEmpty(extStack)) { + return transMixChartDataAntV(xAxisBase, xAxis, new ArrayList<>(), yAxis, view, data, isDrill); + } + + Map map = new HashMap<>(); + + List series = new ArrayList<>(); + for (ChartViewFieldDTO y : yAxis) { + Series series1 = new Series(); + series1.setName(y.getName()); + series1.setType(y.getChartType()); + series1.setData(new ArrayList<>()); + series.add(series1); + } + + for (int i1 = 0; i1 < data.size(); i1++) { + String[] row = data.get(i1); + + StringBuilder a = new StringBuilder(); + if (isDrill) { + a.append(row[xAxis.size() - 1]); + } else { + for (int i = 0; i < xAxis.size(); i++) { + if (i == xAxis.size() - 1) { + a.append(row[i]); + } else { + a.append(row[i]).append("\n"); + } + } + } + + // yAxis最后的数据对应extLabel和extTooltip,将他们从yAxis中去掉,同时转换成动态值 + int size = xAxis.size() + extStack.size() + yAxis.size(); + int extSize = view.getExtLabel().size() + view.getExtTooltip().size(); + + int i = xAxis.size(); + AxisChartDataAntVDTO axisChartDataDTO = new AxisChartDataAntVDTO(); + axisChartDataDTO.setField(a.toString()); + axisChartDataDTO.setName(a.toString()); + axisChartDataDTO.setCategory(row[xAxis.size()]); + + List dimensionList = new ArrayList<>(); + List quotaList = new ArrayList<>(); + + for (int k = 0; k < xAxis.size(); k++) { + ChartDimensionDTO chartDimensionDTO = new ChartDimensionDTO(); + chartDimensionDTO.setId(xAxis.get(k).getId()); + chartDimensionDTO.setValue(row[k]); + dimensionList.add(chartDimensionDTO); + } + ChartDimensionDTO chartDimensionDTO = new ChartDimensionDTO(); + chartDimensionDTO.setId(extStack.get(0).getId()); + chartDimensionDTO.setValue(row[xAxis.size()]); + dimensionList.add(chartDimensionDTO); + axisChartDataDTO.setDimensionList(dimensionList); + + int j = i - xAxis.size(); + int valueIndex = xAxis.size() + extStack.size(); + if (ObjectUtils.isNotEmpty(yAxis)) { + ChartQuotaDTO chartQuotaDTO = new ChartQuotaDTO(); + chartQuotaDTO.setId(yAxis.get(j).getId()); + quotaList.add(chartQuotaDTO); + axisChartDataDTO.setQuotaList(quotaList); + try { + axisChartDataDTO.setValue(StringUtils.isEmpty(row[valueIndex]) ? null : new BigDecimal(row[valueIndex])); + } catch (Exception e) { + axisChartDataDTO.setValue(new BigDecimal(0)); + } + buildDynamicValue(view, axisChartDataDTO, row, size, extSize); + } else { + axisChartDataDTO.setQuotaList(quotaList); + axisChartDataDTO.setValue(new BigDecimal(0)); + } + + series.get(j).getData().add(axisChartDataDTO); + } + + + map.put("data", series); + return map; + } + // 基础图形 public static Map transChartData(List xAxis, List yAxis, ChartViewDTO view, List data, boolean isDrill) { Map map = new HashMap<>(); diff --git a/core/core-frontend/src/components/visualization/UserViewEnlarge.vue b/core/core-frontend/src/components/visualization/UserViewEnlarge.vue index f64e025875..fcaa3ec7f8 100644 --- a/core/core-frontend/src/components/visualization/UserViewEnlarge.vue +++ b/core/core-frontend/src/components/visualization/UserViewEnlarge.vue @@ -64,12 +64,12 @@ show-position="viewDialog" /> -