let uniqueDeviceNames = arr.reduce((acc, item) => {
if (!acc.includes(item.device_name)) {
acc.push(item.device_name);
}
return acc;
}, []);
let arrx = arr.reduce((acc, item) => {
if (!acc.includes(item.time)) {
acc.push(item.time);
}
return acc;
}, []);
// 创建一个空对象来存储数组
let arrays = {};
for (var i = 0; i < uniqueDeviceNames.length; i++) {
// 创建一个新的数组
var newArray = [];
// 向数组中添加元素
arr.forEach((element) => {
if (element.device_name == uniqueDeviceNames[i]) {
newArray.push(element.water_attribute);
}
});
// 将数组保存到对象中
arrays[i] = newArray;
}
this.line(arrx, arrays, uniqueDeviceNames);
},
后端返回的值
- 0: {device_name: "张三", point_code: "1401210", time: "2024-02-14 15:03:27",…}
- 1: {device_name: "李四", point_code: "1401211", time: "2024-02-14 16:03:27",…}
- 2: {device_name: "王五", point_code: "1401212", time: "2024-02-14 17:03:27",…}