Dual Axis One Data set Second is transform of first
-
- Posts: 25
- Joined: Thu Apr 03, 2008 5:51 pm
- Location: Houston, TX, USA
Dual Axis One Data set Second is transform of first
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-)
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-)
-
- 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
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
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
-
- 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
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-)
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-)
-
- Posts: 844
- Joined: Fri Oct 13, 2006 9:29 pm
- Location: Sunnyvale, CA
Re: Dual Axis One Data set Second is transform of first
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
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
Re: Dual Axis One Data set Second is transform of first
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.
-
- 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
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 could try using a NumberFormat with the second axis and assign the same dataset to both axis.
That's actually possible in the latest release (and maybe 1.0.12 too, I forget when it was added).RichardWest wrote:You may need to try to convince the plot that you have two axes but only one dataset.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
-
- 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
Thanx guys - you are just great !
I plan to upgrade to 13 in summer.
B-)
I plan to upgrade to 13 in summer.
B-)
Re: Dual Axis One Data set Second is transform of first
I was doing it with a 1.0.6 release and it still works under 1.0.13.david.gilbert wrote: That's actually possible in the latest release (and maybe 1.0.12 too, I forget when it was added).
-
- 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
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 ....
-
- Posts: 844
- Joined: Fri Oct 13, 2006 9:29 pm
- Location: Sunnyvale, CA
Re: Dual Axis One Data set Second is transform of first
The NumberAxis class has a setNumberFormatOverride method.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 ....
Code: Select all
fahrenheitAxis.setNumberFormatOverride(new FahrenheitNumberFormat());