From 531a3d4eef82100dd50e4eb28776dd165f8f40d6 Mon Sep 17 00:00:00 2001 From: dhy1725534722 <1725534722@qq.com> Date: Tue, 22 Aug 2023 10:17:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sentiment/components/componentLeft.vue | 50 +++++++++++++------ 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/src/views/privateOrder/sentiment/components/componentLeft.vue b/src/views/privateOrder/sentiment/components/componentLeft.vue index 26f7583..4b5e36b 100644 --- a/src/views/privateOrder/sentiment/components/componentLeft.vue +++ b/src/views/privateOrder/sentiment/components/componentLeft.vue @@ -350,6 +350,7 @@ export default { //将敏感和非敏感区分开来 positiveOpinion: [], negativeOpinion: [], + allDate: [], date: [], }; }, @@ -363,8 +364,6 @@ export default { }, }, created() { - //舆情走势图 - this.getyqData(); // 获取舆情信息量统计 this.getyqMsgStats(); }, @@ -442,6 +441,7 @@ export default { // }) this.changeBtn(); this.getFilterData(); + //舆情走势图 this.getyqData(); }, beforeDestroy() { @@ -495,20 +495,42 @@ export default { // 获取舆情走势图的数据 getyqData() { yuqingChart().then((res) => { - console.log(res); + this.allDate = res.data; + //已经排序过的数组 + this.allDate.sort(function (a, b) { + return new Date(a.publishTime) - new Date(b.publishTime); + }); + let arr = []; res.data.forEach((value) => { - if (value.type == 2) { - this.positiveOpinion.push(value.count); - } else if (value.type == 1) { - this.negativeOpinion.push(value.count); - } //把日期存储起来 + arr.push(value.publishTime); + }); + //日期已经处理好了 + this.date = arr.filter(function (item, index) { + //当前元素,在原始数组中的第一个索引==当前索引值,否则返回当前元素 + return arr.indexOf(item) === index; + }); + this.date.forEach((value) => { + let arr2 = res.data.filter((m) => { + return m.publishTime == value; + }); + console.log(arr2); + arr2.forEach((e) => { + if (e.type == 1 && arr2.length < 2) { + this.negativeOpinion.push(e.count); + this.positiveOpinion.push(0); + } else if (e.type == 2 && arr2.length < 2) { + this.positiveOpinion.push(e.count); + this.negativeOpinion.push(0); + } else if (e.type == 1 && arr2.length == 2) { + this.negativeOpinion.push(e.count); + } else if (e.type == 2 && arr2.length == 2) { + this.positiveOpinion.push(e.count); + } + }); }); - // const res = new Map(); - // let arr = res.data.filter( - // (item) => !res.has(item[uniId]) && res.set(item[uniId], 1) - // ); this.lineBox(); + console.log(this.date); console.log(this.negativeOpinion); console.log(this.positiveOpinion); }); @@ -541,7 +563,7 @@ export default { left: "17%", right: "1%", }, - legend: { + length: { data: ["非敏感", "敏感"], top: "3%", right: "2%", @@ -568,7 +590,7 @@ export default { }, xAxis: { // data: this.opinionTime, - data: ["7.23", "7.24", "7.25", "7.26", "7.27", "7.28", "7.29"], + data: this.date, axisLine: { show: true, // 隐藏X轴轴线 lineStyle: {