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 = [];spa
var wd_seriesArr = [];code
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);
屢次循環迭代,獲得:blog
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" }]