处理前的数据:
preValue: {202002: 2.57, 202003: 2.55, 202004: 2.74, 202005: 2.62, 202006: 2.54, 202007: 2.47, 202008: 2.43, 202009: 2.41, 202010: 2.4, 202011: 2.24, 202012: 2.41, 202101: 1.9}
value: {202102: 2.62, 202103: 2.59, 202104: 2.91, 202105: 2.65, 202106: 2.51, 202107: 2.4, 202108: 2.33, 202109: 2.3, 202110: 2.17, 202111: 2.14, 202112: 2.1, 202201: 2.6}
处理后的数据:
curData: (12) [2.59, 2.91, 2.65, 2.51, 2.4, 2.33, 2.3, 2.17, 2.14, 2.1, 2.6, undefined]
p: (12) ['2021-03', '2021-04', '2021-05', '2021-06', '2021-07', '2021-08', '2021-09', '2021-10', '2021-11', '2021-12', '2022-01', '2022-02']
preData: (12) [2.55, 2.74, 2.62, 2.54, 2.47, 2.43, 2.41, 2.4, 2.24, 2.41, 1.9, undefined]
js代码实现:
getLineData (list) {
// console.log(list); 处理前的数据
var p = [], curData = [], preData = [];
var date = new Date();
date.setMonth(date.getMonth() + 1, 1)//获取到所选月份,设置月份
for (var i = 0; i < 12; i++) {
date.setMonth(date.getMonth() - 1);//每次循环一次 月份值减1
var m = date.getMonth() + 1;
m = m < 10 ? "0" + m : m;
p.unshift(date.getFullYear() + "-" + (m));
curData.unshift(list.value[date.getFullYear() + "" + (m)]);
preData.unshift(list.preValue[date.getFullYear() - 1 + "" + (m)]);
}
this.myDate = p
// console.log(this.myDate, '总日期');
// console.log(this.myDate, p, curData, preData, '总日期');
return { p: p, curData: curData, preData: preData }
},