• 数据多js平均时间取固定条数展示,echarts数据多处理数据


    js代码:

    function getfailurerate(start,end,ip) {
        $.ajax( {
            url : "report/getvirtual.action",
            type : "POST",
            data : {
                'ip' : ip,
                'startime' : start,
                'endtime' : end,
            },
            timeout : 180000,
            async : true,
            beforeSend: function(){
                MaskUtil.mask(); 
                var net = new Array();
                var createtime = new Array();
                var lnet = new Array();
                var lnet_out = new Array();
                var net_out = new Array();
                var net_avg = new Array();
                var cpu = new Array();
                var mem = new Array();
                vhostNet(net,net_out,lnet,lnet_out,net_avg,createtime);
                vhostCpu(cpu,createtime);
                vhostMem(mem,createtime);
            },
            success : function(data) {
                MaskUtil.unmask(); 
                var data = eval(data);
                if(data== null || data.length<1){
                    alert("暂无数据!");
                }
                var net = new Array();
                var createtime = new Array();
                var lnet = new Array();
                var lnet_out = new Array();
                var net_out = new Array();
                var net_avg = new Array();
                var cpu = new Array();
                var mem = new Array();
                
                var sum = 0; 
                var count = 0;
                //如果大于三个月
                var smonth = start.substring(8,10);
                var emonth = end.substring(8,10);
    //            if((emonth - smonth) > 3){
                //如果大于多少条
                var item = 1000;//条数
                if(data.length > item){
                    var timestamp = parseInt(new Date().getTime()/1000);
    //                start = start.substring(0,19);如果时间格式有问题时使用
    //                start = start.replace(/-/g,'/'); 
                    var s = new Date(data[0].createtime.substring(0, 16)).getTime();
                    sum = s;
                    var e = new Date(data[data.length-1].createtime.substring(0, 16)).getTime();
                    //计算起止时间的平均值,用来每次添加数据后增长时间
                    count = parseInt((e-s)/item);
                    for(var j = 0 ; j<data.length; j++){
    //                    var sumdate = getTimeDate(sum + count);
                        var sumdate = getTimeDate(sum);//不加count会多一条开始时间的数据
                        var ctime = data[j].createtime.substring(0, 16);
                        var date1 = new Date(sumdate);
                        var date2 = new Date(ctime);
                        //如果所要时间小于数据时间或与数据时间相等,添加数据并增长所要时间
                        if(date1 < date2 || date1 - date2 == 0){
                            net.push(data[j].net);
                            createtime.push(data[j].createtime);
                            lnet.push(data[j].lnet);
                            lnet_out.push(data[j].lnet_out);
                            net_out.push(data[j].net_out);
                            net_avg.push(data[j].net_avg);
                            cpu.push(data[j].cpu);
                            mem.push(data[j].memory);
                            sum = sum + count;
                        }
                    }
                    var sumdate = getTimeDate(sum);
                }else{
                    //如果不符合条件,走普通
                    for(var j = 0 ; j < data.length; j++){
                        net.push(data[j].net);
                        createtime.push(data[j].createtime);
                        lnet.push(data[j].lnet);
                        lnet_out.push(data[j].lnet_out);
                        net_out.push(data[j].net_out);
                        net_avg.push(data[j].net_avg);
                        cpu.push(data[j].cpu);
                        mem.push(data[j].memory);
                    }
                }
                vhostNet(net,net_out,lnet,lnet_out,net_avg,createtime);
                vhostCpu(cpu,createtime);
                vhostMem(mem,createtime);
            }
        });
    }
    function getTimeDate(timedate) {
    //    var s = new Date(d);
    //    var sdate = (s.getFullYear()) + "-" + 
    //       (s.getMonth() + 1) + "-" +
    //       (s.getDate()) + " " + 
    //       (s.getHours()) + ":" + 
    //       (s.getMinutes()) + ":" + 
    //       (s.getSeconds());
    }
    function getTimeDate(timedate) {
        var s = new Date(timedate);
        var date = (s.getFullYear()) + "-" + 
          (s.getMonth() + 1) + "-" +
          (s.getDate()) + " " + 
          (s.getHours()) + ":" + 
          (s.getMinutes());
    //     + ":" + (s.getSeconds());
        return date;
    }
  • 相关阅读:
    .Net常用的命名空间
    Jquery测试纠错笔记
    第一章 学习总结
    Java和C++引用的区别
    gin的墙内开发艺术
    golang几个环境变量的问题
    Leetcode240_搜索二维矩阵II
    Leetcode1358_包含所有三种字符的子字符串数目
    Leetcode1354_多次求和构造目标数组
    Leetcode1353_最多可以参加的会议数目
  • 原文地址:https://www.cnblogs.com/raitorei/p/10904628.html
Copyright © 2020-2023  润新知