自己写的计算时间坐标的代码
来源:互联网 发布:大恒加密软件破解 编辑:程序博客网 时间:2024/05/16 12:52
1 数据库sql查询的数据
2 最终echarts画出来的图
3 代码如下
计算主方法方法
/** * echarts算时间轴代码(算流量的代码),这里的时间间隔为5秒钟,一分钟的流量,totalSize = 12 * ebuStreamList 为EbuStream的集合, EbuStream的属性有totalStream,time * totalSize为x轴有多少点 * startTime 为起始时间 * */private String[] getEbuStream(List<EbuStream> ebuStreamList,int totalSize,String startTime) throws ParseException{String[] totalStreamArray = new String[totalSize];String currentTime = startTime; //起始时间变量int pointer = 0; //时间指针int counter = 0 ;//计数器for(int i = 0 ; i < totalSize ; i ++){ // 遍历开始,为每个点赋值String nextTime = ChartsTimeUtil.getNextTime(currentTime, 1); //下一次时间//校验时间if(ebuStreamList!=null&&ebuStreamList.size()>pointer){String cpuTime = ebuStreamList.get(pointer).getTime();//得到当前流量实体的时间/** * 假设时间为 * currentTime = 2016-05-07 22:10:46 * cpuTime = 2016-05-07 22:10:48 * nextTime = 2016-05-07 22:10:51 * 则cpuTime在currentTime和nextTime之间 * 执行if( ChartsTimeUtil.isBigger(cpuTime, currentTime) && ChartsTimeUtil.isBigger(nextTime, cpuTime) )里面的代码 * * */if( ChartsTimeUtil.isBigger(cpuTime, currentTime) && ChartsTimeUtil.isBigger(nextTime, cpuTime) ){totalStreamArray[i] = ""+ebuStreamList.get(pointer).getTotalStream()+"";pointer++;counter++;}/** * 假设时间为 * cpuTime = 2016-05-07 22:10:45 * currentTime = 2016-05-07 22:10:46 * nextTime = 2016-05-07 22:10:51 * 则cpuTime在currentTime和nextTime的左侧 * 执行else if(ChartsTimeUtil.isBigger(currentTime, cpuTime))里面的代码 * * */else if(ChartsTimeUtil.isBigger(currentTime, cpuTime)){pointer++;nextTime = currentTime;i--;}/** * 假设时间为 * currentTime = 2016-05-07 22:10:46 * nextTime = 2016-05-07 22:10:51 * cpuTime = 2016-05-07 22:10:53 * 则cpuTime在currentTime和nextTime的右侧 * 执行下面else里面的代码 * * */else{totalStreamArray[i] = "";counter++;}}/** * 当ebuStreamList为空的时候执行下面else代码 * */else{totalStreamArray[i] = "";counter++;}currentTime = nextTime; // 当前时间往下移一个点}return totalStreamArray;}
ChartsTimeUtil.getNextTime方法代码
/** * 得到下一个点的时间 * private static Calendar calendar = Calendar.getInstance(); * private static SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); * ChartsSnmpTimerTask.timeFrequency=1000 * 5; // 时间间隔5秒钟 * * **/public static String getNextTime(String currentTime ,int next) throws ParseException{if(currentTime==null||currentTime.replace(" ", "").equals("")) return null;calendar.setTime(simpleDateFormat.parse(currentTime));calendar.set(Calendar.SECOND , calendar.get(Calendar.SECOND) + ( ChartsSnmpTimerTask.timeFrequency / 1000 ) * next );return simpleDateFormat.format(calendar.getTime());}
ChartsTimeUtil.isBigger代码
/** * 比较两个日期之间的大小 * * @param d1 * @param d2 * @return 前者大于后者返回true 反之false * @throws ParseException */ public static boolean isBigger( String time1, String time2) throws ParseException { int result = time1.compareTo(time2);if(result>=0){return true;}else{return false;}}
EbuStream实体类
package com.nufront.euht.web.ebu.model;import java.sql.Timestamp;/** * ebu流量实体 * */public class EbuStream {private String id;private int upstream;private int downstream;private int totalStream;private String time;public String getId() {return id;}public void setId(String id) {this.id = id;}public int getUpstream() {return upstream;}public void setUpstream(int upstream) {this.upstream = upstream;}public int getDownstream() {return downstream;}public void setDownstream(int downstream) {this.downstream = downstream;}public int getTotalStream() {return totalStream;}public void setTotalStream(int totalStream) {this.totalStream = totalStream;}public String getTime() {return time;}public void setTime(String time) {this.time = time;}}
0 0
- 自己写的计算时间坐标的代码
- 自己写的一个计算代码执行时间的函数
- 自己写的代码
- 自己写的frameset代码
- 自己写的分页代码
- 自己写的代码文件
- 自己写的代码:时钟
- 自己写的代码,备忘
- 自己写的代码2
- 自己写的代码生成器
- 汉诺塔代码自己写的
- (原创)分享自己写的几个工具类(五)时间计算工具类
- 计算代码的运行时间
- 自己写的计算群论工具
- 按分钟计算自己的时间
- 自己写的在页面动态时间
- 自己写的TimeHelper javal时间工具
- 自己写的Fibonacci 数列计算代码,基于MATLAB ,递归思想!
- 第七届蓝桥杯—第四题||快速排序
- 【Linux学习笔记】关于ubuntu开机菜单栏和任务栏不见了的有效解决方法
- How To Use Netcat to Establish and Test TCP and UDP Connections on a VPS
- 软考 - 数据库系统工程师
- PickerView frame变化
- 自己写的计算时间坐标的代码
- HTTP GET和POST区别
- linux下文件名后面带有波浪号(~)
- 关于spring 3.0.5的<mvc:resources> 标签的使用
- 331. Verify Preorder Serialization of a Binary Tree
- modbus 资源
- 平均值不等式证明(数学归纳法)
- c++ 中 pair 的 使用方法
- Android通用流行框架大全