数据循环处理重组1

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"
}]

 

posted @ 2018-12-27 11:01  abcByme  阅读(328)  评论(0编辑  收藏  举报