Write your own code to calculate the time coordinates

Source: Internet
Author: User
Tags current time time interval

1 data for database SQL queries



2 Final Echarts draw out of the figure





The 3 code is as follows

Calculating the Main method method

/** * Echarts Calculate the time axis code (calculate the traffic code), here the interval is 5 seconds, a minute of traffic, TotalSize = a ebustreamlist for Ebustream collection, Ebustream properties Totalstream, Time * TotalSize is the x-axis of how many points * startTime is the start times * */private string[] Getebustream (list<ebustream> ebustreamlist,in
		T totalsize,string startTime) throws parseexception{string[] Totalstreamarray = new String[totalsize]; String currenttime = startTime; Start time variable int pointer = 0;  Time pointer int counter = 0;//counter for (int i = 0; i < totalsize; i + +) {//traversal start, assign value to each point String Nexttime = Chartstimeutil.getnexttime (currenttime, 1);//Next time//check time if (Ebustreamli St!=null&&ebustreamlist.size () >pointer) {String CPUTime = ebustreamlist.get (pointer). GetTime ();//Get current stream Time/** of the volume entity * Assuming time is * currenttime = 2016-05-07 22:10:46 * CPUTime = 2016-05-07 22:10:48 * nexttime = 2016-05-07 22:10:51 * Then cputime between CurrentTime and Nexttime * Execute if (Chartstimeutil.isbigger (CPUTime, currenttime) &A mp;& Chartstimeutil.isbigGer (Nexttime, CPUTime)) inside the code * * */if (Chartstimeutil.isbigger (CPUTime, currenttime) && Chartstim
					Eutil.isbigger (Nexttime, CPUTime)) {Totalstreamarray[i] = "" +ebustreamlist.get (pointer). Gettotalstream () + "";
					pointer++;
				counter++; }/** * Assuming time is * CPUTime = 2016-05-07 22:10:45 * currenttime = 2016-05-07 22:10:46 * nexttime = 201 6-05-07 22:10:51 * CPUTime on the left side of CurrentTime and Nexttime * Perform else if (Chartstimeutil.isbigger (CurrentTime, CPUTime)) inside
					The code * * */else if (Chartstimeutil.isbigger (CurrentTime, CPUTime)) {pointer++;
					Nexttime = currenttime;
				i--; }/** * Assuming time is * currenttime = 2016-05-07 22:10:46 * nexttime = 2016-05-07 22:10:51 * CPUTime = 201 6-05-07 22:10:53 * CPUTime on the right side of CurrentTime and Nexttime * Execute the code below else inside * * */else{Total
					Streamarray[i] = "";
				counter++;
		}}/** * Execute the following else code when Ebustreamlist is empty	 * */else{Totalstreamarray[i] = "";
			counter++; } currenttime = Nexttime;
	Move the current time down one point} return totalstreamarray;
	 }

Chartstimeutil.getnexttime Method Code

	/**
	 * Get the next point of time
	 * private static Calendar calendar = Calendar.getinstance (); 
	 * private static SimpleDateFormat simpledateformat=new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
	 * chartssnmptimertask.timefrequency=1000 * 5;  Time interval 5 Seconds
	 * 
	 * **/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 Code

	/**  
	 * Compare the size between two dates 
	 *  
	 * @param d1 
	 * @param D2 
	 * @return The former greater than the latter returns true conversely 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 entity class

Package Com.nufront.euht.web.ebu.model;

Import Java.sql.Timestamp;

/**
 * EBU Traffic Entity * */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;
	}
	
}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.