数据循环处理
程序员文章站
2022-07-06 12:02:41
var wd_series = []; var wd_seriesArr = []; 多次循环迭代,得到: ......
function arrayobj(arr, obj) { var find = false; var temperaturesarrayobj = {}; for (var index in arr) { if (obj.legend == arr[index].name) { temperaturesarrayobj = arr[index]; find = true; } }; if (find) { temperaturesarrayobj.data.push(obj.yaxis); } else { var td = []; td.push(obj.yaxis); temperaturesarrayobj['name'] = obj.legend; temperaturesarrayobj['data'] = td; temperaturesarrayobj['type'] = 'line'; //修改属性 arr.push(temperaturesarrayobj); }; return arr; };
var wd_series = [];
var wd_seriesarr = [];
var temperatures = [{ "legend": "n相温度", "unit": "℃", "yaxis": "20.0", "xaxis": "10:48:45" }, { "legend": "c相温度", "unit": "℃", "yaxis": "19.7", "xaxis": "10:48:45" }, { "legend": "a相温度", "unit": "℃", "yaxis": "19.9", "xaxis": "10:48:45" }, { "legend": "b相温度", "unit": "℃", "yaxis": "20.1", "xaxis": "10:48:45" }], "voltages": [{ "legend": "b相电压", "unit": "v", "yaxis": "229.0", "xaxis": "10:48:45" }, { "legend": "a相电压", "unit": "v", "yaxis": "231.0", "xaxis": "10:48:45" }, { "legend": "c相电压", "unit": "v", "yaxis": "237.0", "xaxis": "10:48:45" }]; function getdataline(temperatures, voltages, currents) { temperatures.map(function(item, i) { wd_seriesarr = arrayobj(wd_series, item); }); };
clearinterval(t); t = window.setinterval(function() { getdataline(); }, 10 * 1000);
多次循环迭代,得到:
var a =[{ data: [20.0,20.0,20.0,20.0,20.0,...], //随着迭代的次数push name: "n相温度", type: "line" },{ data: [19.7,19.7,19.7,19.7,19.7,...],//随着迭代的次数push name: "c相温度", type: "line" },{ data: [19.9,19.9,19.9,19.9,19.9,...],//随着迭代的次数push name: "c相温度", type: "line" },{ data: [20.1,20.1,20.1,20.1,20.1,...],//随着迭代的次数push name: "c相温度", type: "line" }]