改变图表的排列顺序,但是后端不想改数据,就得从前端修改啦。。。。
首先,定义好排序map
echartsSortMap: undefined
定义一个initMap,
this.initMap();
initMap() {
this.echartsSortMap = new Map();
this.echartsSortMap.set("Q", 0);
this.echartsSortMap.set("W", 1);
this.echartsSortMap.set("E", 2);
this.echartsSortMap.set("R", 3);
this.echartsSortMap.set("T", 4);
},
echartsSortMap函数排序(sort排序函数)
sortEchartsDataList() {
return this.echartsDataList.sort((a, b) => {
let sortKey1 = a.sortKey;
let sortKey2 = b.sortKey;
let index1 = this.echartsSortMap.get(sortKey1);
let index2 = this.echartsSortMap.get(sortKey2);
if (index1 > index2) {
return 1;
} else if (index1 < index2) {
return -1;
} else {
return 0;
}
});
}