zoukankan      html  css  js  c++  java
  • 数据循环处理重组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"
    }]
  • 相关阅读:
    qemu 系列
    vuex
    gpio led学习
    [Java] 容器-03 增强的For循环 / Set 方法
    [Java] 容器-02 HashSet 类 / Iterator 接口
    [Java] 容器-01 实现 Comparable 接口 / 重写 equals 与 hashCode (1个图 1个类 3个知识点 6个接口)
    [Java] 常用类-03 File 类 (io 包中的 File) / Enum 类
    [Java] 常用类-02 基础数据类型包装类 / Math 类
    [Java] 常用类-01 String / StringBuffer
    [Java] 数组-05 binarySearch / TestArrayCopy
  • 原文地址:https://www.cnblogs.com/Byme/p/10183794.html
Copyright © 2011-2022 走看看