Is this a limitation of DateAxis?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
atongo
Posts: 10
Joined: Sun Jul 23, 2006 9:53 pm

Is this a limitation of DateAxis?

Post by atongo » Tue Sep 05, 2006 11:33 am

I have created a dynamic chart using the DateAxis as the domain axis. What my chart does is this. I get cumulattive time values and I pass them to the chart(in milliseconds) to update the series at every time step. Everything seem to work fine untill the total time exceeds 24 hours (ie 86400000). i was expecting the tickunits to start again from zero(ie 00:00:00) but after a while a get tick units of strange dates(eg, i see months(jan, feb, etc) and later years starting from 1970). Why does the TickUnits show such values?

Your help will be much appreciated

ato

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Tue Sep 05, 2006 4:11 pm

Java's Date class represents points in time (with millisecond precision) as the number of milliseconds since the start of 1-Jan-1970 GMT. We use the same encoding for the DateAxis class.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

atongo
Posts: 10
Joined: Sun Jul 23, 2006 9:53 pm

Post by atongo » Tue Sep 05, 2006 5:58 pm

Hi Dave,

I get what you mean, however, my problem is with the AutoTickUnit. Why does it show strange labels for values greater than 86400000 milliseconds. how do i configure it to continue to display tick units of the pattern (HH:mm:ss) for values greater than 86400000 milliseconds. I tried to overwrite it with SimpleDateFormat(HH:mm:ss) but it wont work!!!

your insight would be much appreciated

ato

hepzibahr
Posts: 13
Joined: Mon Sep 04, 2006 2:33 pm

Post by hepzibahr » Wed Sep 06, 2006 12:33 pm

Try something like this ... as it worked for me and displayed dates inlieu of those huge numbers

plot.setRangeAxis(new DateAxis("Date"));

Hope this works for DomainAxis too....

But i have a problem with overlapping ..now

jwenting
Posts: 157
Joined: Sat Jul 15, 2006 7:46 am

Post by jwenting » Wed Sep 06, 2006 1:23 pm

what you're seeing is a normal result of your domain values.

For 1 day, the axis will generate time only. For longer values a date is added.
You might add a dateFormatOverride to the axis but I doubt this would give you the results you want (as I guess you want the domain axis to display hours and minutes since the start of your period?).

Best thing to do is probably to create another style of axis and do your own transformation of the values to something you want to display.

atongo
Posts: 10
Joined: Sun Jul 23, 2006 9:53 pm

Post by atongo » Wed Sep 06, 2006 1:40 pm

thanks guys for your contribution, see below a shot of my code:
DateAxis domain = new DateAxis("Time");
// set text for the Y (Population) axis
NumberAxis range = new NumberAxis("Population of Reacting Molecules");
/**
* create an XYPlot object to contain the
* dataset and the axes parameters
*/
XYPlot plot = new XYPlot();

atongo
Posts: 10
Joined: Sun Jul 23, 2006 9:53 pm

Post by atongo » Wed Sep 06, 2006 1:48 pm

sorry about that previous one i did not finish with the code:

// set text for the X (Time) axis of the chart
DateAxis domain = new DateAxis("Time");
// set text for the Y (Population) axis
NumberAxis range = new NumberAxis("Population of Reacting Molecules");
/**
* create an XYPlot object to contain the
* dataset and the axes parameters
*/
XYPlot plot = new XYPlot();
plot.setDataset(dataset);
// set the domain axis
plot.setDomainAxis(domain);
// set the range axis
plot.setRangeAxis(range);

the dataset in an XYSeriesCollection. Now I dont understand why the TickUnits interval continue to increase like that. After the first daythe interval is 1hr, 2 hrs the second day, 4hrs the third and then it moves to days, then i see jan, feb, march..whiles in actual sense the calculated total time i have on my counter reads say 345d 23:45:23 (d mean days here). how can I reflect this on the TickUnit...

your advice is more than appreciated..

atongo

jwenting
Posts: 157
Joined: Sat Jul 15, 2006 7:46 am

Post by jwenting » Thu Sep 07, 2006 7:31 am

as I said, use another axis.
You're NOT trying to display dates, but a number of days which is a quite different thing.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Thu Sep 07, 2006 2:32 pm

atongo wrote:whiles in actual sense the calculated total time i have on my counter reads say 345d 23:45:23 (d mean days here). how can I reflect this on the TickUnit...
First, you'll need a custom subclass of DateFormat to display millisecond values in the format "nnnd hh:mm:ss" where nnn is the number of days since 1-Jan-1970.

Next, you'll need to create your own tick unit collection (take a look at DateAxis.createStandardTickUnits() to see how the default collection is created) and specify your custom date formatter as the formatter for each tick size).
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

atongo
Posts: 10
Joined: Sun Jul 23, 2006 9:53 pm

Post by atongo » Thu Sep 07, 2006 3:55 pm

thanks folk,

I have started working on all your ideas and suggestions. This forum is very educative..



Regards

atongo

Locked