• 数据循环处理重组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"
    }]
  • 相关阅读:
    Ubuntu16.04.1 安装Nginx
    Ubuntu16.04.1 安装Redis-Cluster
    SeekBar的简单使用
    Async异步处理
    SQLite
    Shareprefrence
    android中的主线程
    Fragment的简单使用
    ArrayAdapter的使用
    用Intent传递对数
  • 原文地址:https://www.cnblogs.com/Byme/p/10183794.html
Copyright © 2020-2023  润新知