Write your own echarts code that calculates the time coordinates

Source: Internet
Author: User

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 how many points * startTime is the start times * */private string[] Getebustream (list<ebustream> ebustreamlist,int Total Size,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 (ebustreamlist!=null &&ebustreamlist.size () >pointer) {String CPUTime = ebustreamlist.get (pointer). GetTime ();//Gets the time of the current traffic 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 in CU Between Rrenttime and Nexttime * Execute if (Chartstimeutil.isbigger (CPUTime, currenttime) && Chartstimeutil.isbigger ( Nexttime, CPUTime)) inside the code * * */IF (Chartstimeutil.isbigger (CPUTime, CurrenttiMe) && Chartstimeutil.isbigger (Nexttime, CPUTime)) {Totalstreamarray[i] = "" +ebustreamlist.get (pointer). Gettotalstream () + "";p ointer++;counter++;} /** * Assuming time is * CPUTime = 2016-05-07 22:10:45 * currenttime = 2016-05-07 22:10:46 * nexttime = 2016-05-07 22:10:51 * then Cputim E on the left side of CurrentTime and Nexttime * Execute the code inside the Else if (Chartstimeutil.isbigger (CurrentTime, CPUTime)) * */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 = 2016-05-07 22:10:53 * then Cputim E on the right side of CurrentTime and Nexttime * Execute the code below else inside * * */else{totalstreamarray[i] = ""; counter++;}} /** * When Ebustreamlist is empty execute the following else code * */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 {  

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 () {R Eturn 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;}}




Self-written code that calculates the time coordinates of Echarts

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.