diff --git a/backend/src/main/java/io/dataease/service/chart/ChartViewService.java b/backend/src/main/java/io/dataease/service/chart/ChartViewService.java index b9a8d478c6..3eb3b5af78 100644 --- a/backend/src/main/java/io/dataease/service/chart/ChartViewService.java +++ b/backend/src/main/java/io/dataease/service/chart/ChartViewService.java @@ -478,28 +478,31 @@ public class ChartViewService { // 1,处理当期数据;2,根据type计算上一期数据;3,根据resultData计算结果 Map currentMap = new LinkedHashMap<>(); for (String[] item : data) { - currentMap.put(item[timeIndex], item[dataIndex]); + String[] dimension = Arrays.copyOfRange(item, 0, checkedField.size()); + currentMap.put(StringUtils.join(dimension, "-"), item[dataIndex]); } - Iterator> iterator = currentMap.entrySet().iterator(); - int index = 0; - while (iterator.hasNext()) { - Map.Entry next = iterator.next(); - String cTime = next.getKey(); - String cValue = next.getValue(); + for (int index = 0; index < data.size(); index++) { + String[] item = data.get(index); + String cTime = item[timeIndex]; + String cValue = item[dataIndex]; + // 获取计算后的时间,并且与所有维度拼接 String lastTime = calcLastTime(cTime, compareCalc.getType(), timeField.getDateStyle()); - String lastValue = currentMap.get(lastTime); + String[] dimension = Arrays.copyOfRange(item, 0, checkedField.size()); + dimension[timeIndex] = lastTime; + + String lastValue = currentMap.get(StringUtils.join(dimension, "-")); if (StringUtils.isEmpty(cValue) || StringUtils.isEmpty(lastValue)) { - data.get(index)[dataIndex] = null; + item[dataIndex] = null; } else { if (StringUtils.equalsIgnoreCase(resultData, "sub")) { - data.get(index)[dataIndex] = new BigDecimal(cValue).subtract(new BigDecimal(lastValue)).toString(); + item[dataIndex] = new BigDecimal(cValue).subtract(new BigDecimal(lastValue)).toString(); } else if (StringUtils.equalsIgnoreCase(resultData, "percent")) { - if (StringUtils.isEmpty(lastValue)) { - data.get(index)[dataIndex] = null; + if (Integer.parseInt(lastValue) == 0) { + item[dataIndex] = null; } else { - data.get(index)[dataIndex] = new BigDecimal(cValue) + item[dataIndex] = new BigDecimal(cValue) .divide(new BigDecimal(lastValue), 2, RoundingMode.HALF_UP) .subtract(new BigDecimal(1)) .setScale(2, RoundingMode.HALF_UP) @@ -507,9 +510,7 @@ public class ChartViewService { } } } - index++; } - } } } diff --git a/frontend/src/views/chart/components/compare/CompareEdit.vue b/frontend/src/views/chart/components/compare/CompareEdit.vue index 988b372323..aa9916a684 100644 --- a/frontend/src/views/chart/components/compare/CompareEdit.vue +++ b/frontend/src/views/chart/components/compare/CompareEdit.vue @@ -63,10 +63,8 @@ export default { // 过滤xaxis,extStack所有日期字段 initFieldList() { const xAxis = JSON.parse(this.chart.xaxis) - const extStack = JSON.parse(this.chart.extStack) const t1 = xAxis.filter(ele => { return ele.deType === 1 }) - const t2 = extStack.filter(ele => { return ele.deType === 1 }) - this.fieldList = t1.concat(t2) + this.fieldList = t1 // 如果没有选中字段,则默认选中第一个 if ((!this.compareItem.compareCalc.field || this.compareItem.compareCalc.field === '') && this.fieldList.length > 0) { this.compareItem.compareCalc.field = this.fieldList[0].id diff --git a/frontend/src/views/chart/components/drag-item/QuotaExtItem.vue b/frontend/src/views/chart/components/drag-item/QuotaExtItem.vue index 7684e24757..294a72aa45 100644 --- a/frontend/src/views/chart/components/drag-item/QuotaExtItem.vue +++ b/frontend/src/views/chart/components/drag-item/QuotaExtItem.vue @@ -97,15 +97,15 @@ - - {{ $t('chart.yoy_label') }} + + {{ $t('chart.quick_calc') }} ({{ !item.compareCalc ? $t('chart.none') : $t('chart.' + item.compareCalc.type) }}) {{ $t('chart.none') }} - {{ $t('commons.setting') }}... + {{ $t('chart.yoy_label') }}... @@ -191,14 +191,10 @@ export default { }, isEnableCompare() { const xAxis = JSON.parse(this.chart.xaxis) - const extStack = JSON.parse(this.chart.extStack) const t1 = xAxis.filter(ele => { return ele.deType === 1 }) - const t2 = extStack.filter(ele => { - return ele.deType === 1 - }) - if (t1.length > 0 || t2.length > 0) { + if (t1.length > 0 && this.chart.type !== 'text' && this.chart.type !== 'gauge' && this.chart.type !== 'liquid') { this.disableEditCompare = false } else { this.disableEditCompare = true diff --git a/frontend/src/views/chart/components/drag-item/QuotaItem.vue b/frontend/src/views/chart/components/drag-item/QuotaItem.vue index 38855fcece..8c8d53e8b9 100644 --- a/frontend/src/views/chart/components/drag-item/QuotaItem.vue +++ b/frontend/src/views/chart/components/drag-item/QuotaItem.vue @@ -97,15 +97,15 @@ - - {{ $t('chart.yoy_label') }} + + {{ $t('chart.quick_calc') }} ({{ !item.compareCalc ? $t('chart.none') : $t('chart.' + item.compareCalc.type) }}) {{ $t('chart.none') }} - {{ $t('commons.setting') }}... + {{ $t('chart.yoy_label') }}... @@ -188,14 +188,10 @@ export default { }, isEnableCompare() { const xAxis = JSON.parse(this.chart.xaxis) - const extStack = JSON.parse(this.chart.extStack) const t1 = xAxis.filter(ele => { return ele.deType === 1 }) - const t2 = extStack.filter(ele => { - return ele.deType === 1 - }) - if ((t1.length + t2.length === 1) && this.chart.type !== 'text' && this.chart.type !== 'gauge' && this.chart.type !== 'liquid') { + if (t1.length > 0 && this.chart.type !== 'text' && this.chart.type !== 'gauge' && this.chart.type !== 'liquid') { this.disableEditCompare = false } else { this.disableEditCompare = true