How to display time in X-axis

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
remast
Posts: 1
Joined: Fri Jun 03, 2005 11:58 am

How to display time in X-axis

Post by remast » Fri Jun 03, 2005 12:02 pm

Hi,

I need to display a time in the x-axis. The format should be HH:mm:ss.

My data is the number of seconds for x and a value for y. Instead of displaying the number of seconds I need to display a time in the format HH:mm:ss.

How can I do that?

Jan

kulsi
Posts: 7
Joined: Sat Nov 20, 2004 7:53 pm

Post by kulsi » Mon Jun 06, 2005 6:57 am

Code: Select all

SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
 Date d  = new Date(time); 
Second sec = 	 getSecond(sdf.format(d));

series.add(sec, value);
Here is my getSecond function:

Code: Select all

protected static Second getSecond( String sec )
{
  try
  {
     CSVTokenizer ct = new CSVTokenizer (sec, ":"); 
    
     //get hour
     int hour = Integer.parseInt(ct.nextToken() );

     //get minute
     int min = Integer.parseInt(ct.nextToken() );

     //get seconds
     int secs = Integer.parseInt(ct.nextToken() );

     //#TODO Use current day, month and year of timestamp 
     return new Second (secs, min, hour, 1, 1, 2005);
  }
  catch ( Exception e )
  {
     e.printStackTrace();
  }
   return null;
}//end getsec
time is along value of milliseconds (unix time)

Locked