From ccc3d7c6165fca5dc20900778909eac075e0d43d Mon Sep 17 00:00:00 2001 From: LokerL Date: Sun, 13 Oct 2024 11:07:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=95=B0=E6=8D=AE=E7=BB=9F=E8=AE=A1-?= =?UTF-8?q?=E5=AF=B9=E6=AF=94=E5=88=86=E6=9E=90=EF=BC=8C=E6=8C=89=E6=9C=88?= =?UTF-8?q?=E4=BB=BD=E6=8E=92=E5=BA=8F=E6=95=B0=E6=8D=AE=E5=B9=B6=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=9B=BE=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 按照月份正确排序数据,并更新图表以反映排序后的数据。 --- .../views/dataStatistics/comparison/index.vue | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/ruoyi-ui/src/views/dataStatistics/comparison/index.vue b/ruoyi-ui/src/views/dataStatistics/comparison/index.vue index 1c21d19..ae7b684 100644 --- a/ruoyi-ui/src/views/dataStatistics/comparison/index.vue +++ b/ruoyi-ui/src/views/dataStatistics/comparison/index.vue @@ -102,7 +102,23 @@ export default { return; } const { data } = res; - this.chartData.series.data = Object.keys(data).map((key) => { + // 按照 month 正确排序 + function sortDataByMonth(data) { + // 遍历对象的每个键 + for (const key in data) { + if (data.hasOwnProperty(key)) { + // 对每个键对应的数组进行排序 + data[key].sort((a, b) => { + // 比较 month 属性 + return new Date(a.month) - new Date(b.month); + }); + } + } + return data; + } + const sortedData = sortDataByMonth(data); + + this.chartData.series.data = Object.keys(sortedData).map((key) => { return { name: this.deptList.find((item) => item.deptId === parseInt(key))?.deptName, type: "line",