数据循环处理

2018-12-27 07:41:58来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

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

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:JavaScript中数组的增删改查以及应用方式

下一篇:(JavaScript基础向)日常小发现:forEach等函数的第二个参数的