Dual Axis One Data set Second is transform of first

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
bruehlicke
Posts: 25
Joined: Thu Apr 03, 2008 5:51 pm
Location: Houston, TX, USA

Dual Axis One Data set Second is transform of first

Post by bruehlicke » Thu May 07, 2009 3:30 pm

Suppose you have one dataset which you would like to represent with 2 axis. Simple case. Dataset is representing degree in celsius. You would like to have a dual axis chart with Celsius the one and Fahrenheit the second.

Currently the (naive) solution I am using is to create a second dataset which contains the transformed values of the first and add it as usual and set the second series to false (setSeriesVisuble(1,false))

I could nto find any way of defining a new axis which is just a simple tranmsform of the first axis - is there ? If not - would be a nice new feature.

Thanx
B-)

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

Re: Dual Axis One Data set Second is transform of first

Post by david.gilbert » Thu May 07, 2009 3:59 pm

I've actually thought about this before. I'd like to create a new NumberAxis that has two scales - one is the "real" scale and the other is the "display" scale. Thus, you could have a dataset with values in degrees Celsius, but display the tick labels using Fahrenheit. I just never found the time to implement this...
David Gilbert
JFreeChart Project Leader

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

bruehlicke
Posts: 25
Joined: Thu Apr 03, 2008 5:51 pm
Location: Houston, TX, USA

Re: Dual Axis One Data set Second is transform of first

Post by bruehlicke » Thu May 07, 2009 4:46 pm

I think the idea should not be to allow to have a NumberAxis having multiple scales but rather allow sending down a Transform object and Number axis as constructor. Maybe something like

NumberAxis first = ...
Transformation valueTransformer = new Transformation(...);
... somehow alow to add some functions to the Transformation class

NumberAxis second = new NumberAxis(first, valueTransformer);


Now the second axis uses the first to clone itself or have a reference to it and uses the Transformation object as rules for how values get represented in this scale.

B-)

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Re: Dual Axis One Data set Second is transform of first

Post by RichardWest » Thu May 07, 2009 5:51 pm

You could try using a NumberFormat with the second axis and assign the same dataset to both axis. I do not have the time to think through all the details though. You may need to try to convince the plot that you have two axes but only one dataset.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

jleech
Posts: 62
Joined: Fri Oct 26, 2007 9:18 pm

Re: Dual Axis One Data set Second is transform of first

Post by jleech » Thu May 07, 2009 5:58 pm

I do this all the time. I create 2 y-axis but only have 1 dataset. I set the min and max of both axis appropriately using setRangeWithMargins(). There is an edge case, when there is no data in the dataset, you've got to set the range to something like 0, 0.0000000001 on the 2nd axis, or JFreeChart won't display anything, not even the 1st axis. It would be nice if this were a built-in feature of JFreeChart.

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

Re: Dual Axis One Data set Second is transform of first

Post by david.gilbert » Thu May 07, 2009 5:58 pm

RichardWest wrote:You could try using a NumberFormat with the second axis and assign the same dataset to both axis.
I think that would work, but I'd consider it an abuse of the NumberFormat feature (although I've probably done something similar already!)
RichardWest wrote:You may need to try to convince the plot that you have two axes but only one dataset.
That's actually possible in the latest release (and maybe 1.0.12 too, I forget when it was added).
David Gilbert
JFreeChart Project Leader

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

bruehlicke
Posts: 25
Joined: Thu Apr 03, 2008 5:51 pm
Location: Houston, TX, USA

Re: Dual Axis One Data set Second is transform of first

Post by bruehlicke » Thu May 07, 2009 6:12 pm

Thanx guys - you are just great !

I plan to upgrade to 13 in summer.

B-)

jleech
Posts: 62
Joined: Fri Oct 26, 2007 9:18 pm

Re: Dual Axis One Data set Second is transform of first

Post by jleech » Thu May 07, 2009 8:08 pm

david.gilbert wrote: That's actually possible in the latest release (and maybe 1.0.12 too, I forget when it was added).
I was doing it with a 1.0.6 release and it still works under 1.0.13.

bruehlicke
Posts: 25
Joined: Thu Apr 03, 2008 5:51 pm
Location: Houston, TX, USA

Re: Dual Axis One Data set Second is transform of first

Post by bruehlicke » Fri May 08, 2009 7:26 pm

Richard, could you just give me a hint how one could " using a NumberFormat with the second axis " ? I have difficult to see how these two classes can work together ....

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Re: Dual Axis One Data set Second is transform of first

Post by RichardWest » Fri May 08, 2009 7:37 pm

bruehlicke wrote:Richard, could you just give me a hint how one could " using a NumberFormat with the second axis " ? I have difficult to see how these two classes can work together ....
The NumberAxis class has a setNumberFormatOverride method.

Code: Select all

fahrenheitAxis.setNumberFormatOverride(new FahrenheitNumberFormat());

Locked