Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Change X-axis label's value in TimeSeries chart (jfreechart)

Posted on 2004-04-12
13
Medium Priority
?
3,790 Views
Last Modified: 2007-12-19
Sample code as below:

XYPlot plot = chart.getXYPlot();
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setTickUnit(new DateTickUnit(DateTickUnit.HOUR, 1,new SimpleDateFormat("dd-MMM HH:mm")));

the above coding will display the dd-MMM HH:mm as my X-axis label. just wonder is there anyway to display the dd-MMM as X-axis label if the dd-MMM is enter to a new date.

thanks
0
Comment
Question by:Kennywen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
13 Comments
 
LVL 30

Expert Comment

by:Mayank S
ID: 10804340
Do you want to change the display on some specific event or automatically, after a period of time? If so, you might need a separate thread and keep a timer.
0
 

Author Comment

by:Kennywen
ID: 10804355
axis.setTickUnit(new DateTickUnit(DateTickUnit.HOUR, 1,new SimpleDateFormat("dd-MMM HH:mm")));

actually the above code will display the date and time on the X-axis label. E.g. 12-Apr 18:16, 12-Apr 19:16, 12-Apr 20:16, 12-Apr 21:16, 12-Apr 22:16 and so on. But i want to display the date only when the date is not exist recently on the X-axis label E.g. 12-Apr 18:16, 19:16, 20:16, 21:16, 22:16, 23:16, 13-Apr 00:16, 01:16 and so on. Any idea to doing above example?

thanks
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10804404
Perhaps you can display the date once and then use: new SimpleDateFormat ( "HH:mm" ) ) ) ;
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Kennywen
ID: 10804425
can you provide more code for me?

thanks
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10804562
Just that:

>> axis.setTickUnit(new DateTickUnit(DateTickUnit.HOUR, 1,new SimpleDateFormat("dd-MMM HH:mm")));

would become:

axis.setTickUnit ( new DateTickUnit ( DateTickUnit.HOUR, 1, new SimpleDateFormat ( "HH:mm" ) ) ) ;
0
 

Author Comment

by:Kennywen
ID: 10809862
>> axis.setTickUnit ( new DateTickUnit ( DateTickUnit.HOUR, 1, new SimpleDateFormat ( "HH:mm" ) ) ) ;

this will display the HH:mm as the X-axis label. but i want to display the date also when it's a new date.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10810502
Do you have some method/ means for reading the contents which have been displayed? If so, then it might be solved.
0
 

Author Comment

by:Kennywen
ID: 10810768
Currently i don't have any solution yet because:
>> axis.setTickUnit ( new DateTickUnit ( DateTickUnit.HOUR, 1, new SimpleDateFormat ( "HH:mm" ) ) ) ;
will set the HH:mm as the X-axis label and

>> axis.setTickUnit ( new DateTickUnit ( DateTickUnit.HOUR, 1, new SimpleDateFormat ( "dd:MMM" ) ) ) ;
will set the dd:MMM as the X-axis label

so how can i display the dd:MMM when it's a new day (E.g. 13 - Apr, 14 - Apr and so on) but display the HH:mm as the X-axis label

E.g.
12-Apr 18:16, 19:16, 20:16, 21:16, 22:16, 23:16, 13-Apr 00:16, 01:16
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10810989
Try this:

Calendar cal = Calendar.getInstance () ;
String format = ( cal.get ( Calendar.HOUR ) == 0 && cal.get ( Calendar.MINUTE ) == 0 ) ? "dd-MMM HH:mm" : "HH:mm" ;

axis.setTickUnit ( new DateTickUnit ( DateTickUnit.HOUR, 1, new SimpleDateFormat ( format ) ) ) ;
0
 

Author Comment

by:Kennywen
ID: 10811020
tested and it display the HH:mm as my X-axis label. But the date is not appear in the x-axis.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10811711
It will display a new date when a new day will start. Set your system time to something like 23:59 and see if it prints the date when a new date starts.
0
 

Author Comment

by:Kennywen
ID: 10811726
X-axis label is depend on my database's data and one of my database column is the date.
0
 
LVL 30

Accepted Solution

by:
Mayank S earned 200 total points
ID: 10811786
Then you can try this:

Calendar cal = Calendar.getInstance () ;
cal.setTime ( theDateFromTheDatabase ) ;
String format = ( cal.get ( Calendar.HOUR ) == 0 && cal.get ( Calendar.MINUTE ) == 0 ) ? "dd-MMM HH:mm" : "HH:mm" ;
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

664 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question