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"
    }]
  • 相关阅读:
    Quarts 执行定时任务失败(.job.entity.ScheduleJobEntity cannot be cast to com.)
    Map与String互相转化
    weui中的picker滑动报错
    weui中的picker使用js进行动态绑定数据
    ajax跨域问题解决方案(jsonp的使用)
    pdm文件打开方式
    删除静态页面的html
    js同时获取多个共同class内容标签内容集合
    内外网同时使用
    win10重装系统修改信息
  • 原文地址:https://www.cnblogs.com/Byme/p/10183794.html
Copyright © 2011-2022 走看看