How to print a duration on Y-axis

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
fjoseph
Posts: 2
Joined: Fri Jun 16, 2006 4:51 pm

How to print a duration on Y-axis

Post by fjoseph » Mon Jun 19, 2006 5:04 pm

Hi,

Currently, I'm using a Bar-Chart in witch I want to print a duration in the Y-axis.
The duration is in seconds and I want to apply a pattern on it, like this :
what I have -> what I want to be printed
235380 sec -> 65h 23min
3456 sec -> 57min 36sec
...

Is there a DurationAxis like the DateAxis ?
Is it possible to apply a pattern on the values of NumberAxis ?

"Help Me Obi-Wan Kenobi, You're My Only Hope !!"

P.S. : it's for a rush-work !!

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 » Mon Jun 19, 2006 5:11 pm

You need to create a subclass of Java's NumberFormat that can convert your values (in seconds) into a string in the form "XXh YYm ZZsec".
David Gilbert
JFreeChart Project Leader

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

fjoseph
Posts: 2
Joined: Fri Jun 16, 2006 4:51 pm

Post by fjoseph » Tue Jun 20, 2006 9:22 am

It's ok !!

I have just overloaded the format method of my subclass.
And that work !!

It's a good tip !! 8)

Thanks !!

cenicienta
Posts: 15
Joined: Mon Jun 26, 2006 8:31 pm
Location: Paris

Post by cenicienta » Mon Jun 26, 2006 8:37 pm

Hi,

I create a subclass of Java's NumberFormat as you said and i try to apply this new format to my Chart with this code :

Code: Select all

NumberAxis numberAxis = new NumberAxis("CPU"); 
numberAxis.setTickUnit(new NumberTickUnit(1, new DurationFormat())) ;
or this :

Code: Select all

NumberAxis numberAxis = new NumberAxis("CPU"); 
numberAxis.setNumberFormatOverride(new DurationFormat());
but that's doesn't work.

Can you help me please ?

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 Jun 27, 2006 9:32 am

The code you posted will make JFreeChart use your DurationFormat class...what happens inside DurationFormat, I do not know.
David Gilbert
JFreeChart Project Leader

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

cenicienta
Posts: 15
Joined: Mon Jun 26, 2006 8:31 pm
Location: Paris

Post by cenicienta » Tue Jun 27, 2006 1:12 pm

Thanks for your response. :wink:
But my class DurationFormat works well out of JFreeChart.
I don't understand what happens. :?

cenicienta
Posts: 15
Joined: Mon Jun 26, 2006 8:31 pm
Location: Paris

Post by cenicienta » Tue Jun 27, 2006 8:55 pm

This code works :

Code: Select all

        NumberAxis numberAxis = (NumberAxis) xyplot.getRangeAxis() ;
        numberAxis.setNumberFormatOverride(new DurationFormat());
        numberAxis.setLabel("CPU") ;
Thanks a lot. :wink:

cenicienta
Posts: 15
Joined: Mon Jun 26, 2006 8:31 pm
Location: Paris

Post by cenicienta » Wed Jun 28, 2006 11:53 am

Hi,

Now, i try to generate tooltip for my Time Series Chart using my format DurationFormat.

This is my code :

Code: Select all

XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)xyplot.getRenderer();
xylineandshaperenderer.setBaseShapesVisible(true);
xylineandshaperenderer.setToolTipGenerator(new StandardXYToolTipGenerator("CPU",new SimpleDateFormat("MMM-yyyy"),new DurationFormat()));
It doesn't work because only "CPU" appears in tooltip. :?

If i use this code :

Code: Select all

xylineandshaperenderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
tooltip is generated but of course without my format. :oops:

Can you tell me whats' wrong in my code please ?
Last edited by cenicienta on Thu Jun 29, 2006 8:49 pm, edited 1 time in total.

cenicienta
Posts: 15
Joined: Mon Jun 26, 2006 8:31 pm
Location: Paris

Post by cenicienta » Thu Jun 29, 2006 8:48 pm

Nobody can help me ? :wink:

Locked