diff --git a/core/backend/src/main/java/io/dataease/service/chart/ChartViewService.java b/core/backend/src/main/java/io/dataease/service/chart/ChartViewService.java index fbbbae53d0..540ac9a012 100644 --- a/core/backend/src/main/java/io/dataease/service/chart/ChartViewService.java +++ b/core/backend/src/main/java/io/dataease/service/chart/ChartViewService.java @@ -73,6 +73,7 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.text.SimpleDateFormat; import java.util.*; +import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.ReentrantLock; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -1447,6 +1448,78 @@ public class ChartViewService { .divide(sum, 8, RoundingMode.HALF_UP) .toString(); } + } else if (StringUtils.equalsAnyIgnoreCase(compareCalc.getType(), "accumulate")) { + // 累加 + if (data.isEmpty()) { + break; + } + if (StringUtils.containsAny(view.getType(), "group", "stack")) { + if (xAxisBase.isEmpty()) { + break; + } + if (StringUtils.containsIgnoreCase(view.getType(), "stack") && extStack.isEmpty()) { + break; + } + if (StringUtils.containsIgnoreCase(view.getType(), "group") && xAxisExt.isEmpty() ) { + break; + } + final Map mainIndexMap = new HashMap<>(); + final List> mainMatrix = new ArrayList<>(); + List finalXAxisBase = xAxisBase; + data.forEach(item -> { + String[] mainAxisArr = Arrays.copyOfRange(item, 0, finalXAxisBase.size()); + String mainAxis = StringUtils.join(mainAxisArr, '-'); + Integer index = mainIndexMap.get(mainAxis); + if (index == null) { + mainIndexMap.put(mainAxis, mainMatrix.size()); + List tmp = new ArrayList<>(); + tmp.add(item); + mainMatrix.add(tmp); + } else { + List tmp = mainMatrix.get(index); + tmp.add(item); + } + }); + int finalDataIndex = dataIndex; + int subEndIndex = finalXAxisBase.size(); + if (StringUtils.containsIgnoreCase(view.getType(), "group")) { + subEndIndex += xAxisExt.size(); + } + if (StringUtils.containsIgnoreCase(view.getType(), "stack")) { + subEndIndex += extStack.size(); + } + int finalSubEndIndex = subEndIndex; + //滑动累加 + for (int k = 1; k < mainMatrix.size(); k++) { + List preDataItems = mainMatrix.get(k - 1); + List curDataItems = mainMatrix.get(k); + Map preDataMap = new HashMap<>(); + preDataItems.forEach(preDataItem -> { + String[] groupStackAxisArr = Arrays.copyOfRange(preDataItem, finalXAxisBase.size(), finalSubEndIndex); + String groupStackAxis = StringUtils.join(groupStackAxisArr, '-'); + preDataMap.put(groupStackAxis, new BigDecimal(preDataItem[finalDataIndex])); + }); + curDataItems.forEach(curDataItem -> { + String[] groupStackAxisArr = Arrays.copyOfRange(curDataItem, finalXAxisBase.size(), finalSubEndIndex); + String groupStackAxis = StringUtils.join(groupStackAxisArr, '-'); + BigDecimal preValue = preDataMap.get(groupStackAxis); + if (preValue != null) { + curDataItem[finalDataIndex] = new BigDecimal(curDataItem[finalDataIndex]) + .add(preValue) + .toString(); + } + }); + } + } else { + final int index = dataIndex; + final AtomicReference accumValue = new AtomicReference<>(new BigDecimal(0)); + data.forEach(item -> { + BigDecimal curVal = new BigDecimal(item[index]); + BigDecimal curAccumValue = accumValue.get().add(curVal); + item[index] = curAccumValue.toString(); + accumValue.set(curAccumValue); + }); + } } } } diff --git a/core/frontend/src/lang/en.js b/core/frontend/src/lang/en.js index 69889fad94..2eab233a5a 100644 --- a/core/frontend/src/lang/en.js +++ b/core/frontend/src/lang/en.js @@ -1373,6 +1373,7 @@ export default { select_chart_type: 'Select Chart Type', recover: 'Reset', yoy_label: 'YOY/MOM', + accumulate: 'Accumulate', yoy_setting: 'Setting', pls_select_field: 'Select Field', compare_date: 'Compare Date', diff --git a/core/frontend/src/lang/tw.js b/core/frontend/src/lang/tw.js index 4ca73778db..ee1634a8ce 100644 --- a/core/frontend/src/lang/tw.js +++ b/core/frontend/src/lang/tw.js @@ -1371,6 +1371,7 @@ export default { select_chart_type: '選擇圖表類型', recover: '重置', yoy_label: '同比/環比', + accumulate: '累加', yoy_setting: '同環比設置', pls_select_field: '請選擇字段', compare_date: '對比日期', diff --git a/core/frontend/src/lang/zh.js b/core/frontend/src/lang/zh.js index 47f81a2485..f063a91ede 100644 --- a/core/frontend/src/lang/zh.js +++ b/core/frontend/src/lang/zh.js @@ -1372,6 +1372,7 @@ export default { recover: '重置', yoy_label: '同比/环比', yoy_setting: '同环比设置', + accumulate: '累加', pls_select_field: '请选择字段', compare_date: '对比日期', compare_type: '对比类型', diff --git a/core/frontend/src/views/chart/chart/util.js b/core/frontend/src/views/chart/chart/util.js index cc3f5d5f63..2679964e18 100644 --- a/core/frontend/src/views/chart/chart/util.js +++ b/core/frontend/src/views/chart/chart/util.js @@ -3657,7 +3657,7 @@ export function getColors(chart, colors, reset) { if (chart.data) { const data = chart.data.data const s = [] - data.forEach((cur) => { + data?.forEach((cur) => { if (s.indexOf(cur.category) < 0) { s.push(cur.category) } diff --git a/core/frontend/src/views/chart/components/ChartComponentG2.vue b/core/frontend/src/views/chart/components/ChartComponentG2.vue index 246982c139..3d4d5a2658 100644 --- a/core/frontend/src/views/chart/components/ChartComponentG2.vue +++ b/core/frontend/src/views/chart/components/ChartComponentG2.vue @@ -97,7 +97,6 @@ export default { }, data() { return { - myChart: null, chartId: uuid.v1(), showTrackBar: true, trackBarStyle: { diff --git a/core/frontend/src/views/chart/components/ChartComponentS2.vue b/core/frontend/src/views/chart/components/ChartComponentS2.vue index 8e2360272d..2cb9548a74 100644 --- a/core/frontend/src/views/chart/components/ChartComponentS2.vue +++ b/core/frontend/src/views/chart/components/ChartComponentS2.vue @@ -175,7 +175,6 @@ export default { }, tableData: [], showPage: false, - scrollTimer: null, scrollTop: 0, remarkCfg: { show: false, @@ -239,7 +238,6 @@ export default { this.preDraw() }, beforeDestroy() { - clearInterval(this.scrollTimer) window.removeEventListener('resize', this.chartResize) this.myChart?.facet.timer?.stop() this.myChart?.destroy?.() @@ -524,7 +522,6 @@ export default { }, initScroll() { - clearTimeout(this.scrollTimer) const customAttr = JSON.parse(this.chart.customAttr) const senior = JSON.parse(this.chart.senior) if (senior?.scrollCfg?.open && (this.chart.type === 'table-normal' || (this.chart.type === 'table-info' && !this.showPage))) { diff --git a/core/frontend/src/views/chart/components/dragItem/QuotaItem.vue b/core/frontend/src/views/chart/components/dragItem/QuotaItem.vue index 4faea534c8..0f4e27c35c 100644 --- a/core/frontend/src/views/chart/components/dragItem/QuotaItem.vue +++ b/core/frontend/src/views/chart/components/dragItem/QuotaItem.vue @@ -179,6 +179,10 @@ :disabled="quotaViews.indexOf(chart.type) > -1" :command="beforeQuickCalc('percent')" >{{ $t('chart.percent') }} + {{ $t('chart.accumulate') }} @@ -418,6 +422,10 @@ export default { this.item.compareCalc.type = 'percent' this.$emit('onQuotaItemChange', this.item) break + case 'accumulate': + this.item.compareCalc.type = 'accumulate' + this.$emit('onQuotaItemChange', this.item) + break default: break }