How to print a duration on Y-axis
How to print a duration on Y-axis
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 !!
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 !!
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
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
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- Posts: 15
- Joined: Mon Jun 26, 2006 8:31 pm
- Location: Paris
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 :
or this :
but that's doesn't work.
Can you help me please ?
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())) ;
Code: Select all
NumberAxis numberAxis = new NumberAxis("CPU");
numberAxis.setNumberFormatOverride(new DurationFormat());
Can you help me please ?
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
The code you posted will make JFreeChart use your DurationFormat class...what happens inside DurationFormat, I do not know.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- Posts: 15
- Joined: Mon Jun 26, 2006 8:31 pm
- Location: Paris
-
- Posts: 15
- Joined: Mon Jun 26, 2006 8:31 pm
- Location: Paris
This code works :
Thanks a lot. 
Code: Select all
NumberAxis numberAxis = (NumberAxis) xyplot.getRangeAxis() ;
numberAxis.setNumberFormatOverride(new DurationFormat());
numberAxis.setLabel("CPU") ;

-
- Posts: 15
- Joined: Mon Jun 26, 2006 8:31 pm
- Location: Paris
Hi,
Now, i try to generate tooltip for my Time Series Chart using my format DurationFormat.
This is my code :
It doesn't work because only "CPU" appears in tooltip.
If i use this code :
tooltip is generated but of course without my format.
Can you tell me whats' wrong in my code please ?
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()));

If i use this code :
Code: Select all
xylineandshaperenderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());

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.