A discussion forum for JFreeChart (a 2D chart library for the Java platform).
-
mhilpert
- Posts: 497
- Joined: Wed Apr 02, 2003 1:57 pm
- Location: Germany
Post
by mhilpert » Fri Apr 01, 2005 3:46 pm
I wrote an enhanced LogarithmicAxis and a PercentageAxis that is suitable for financial charts:
[1891921] Enhanced LogarithmicAxis
With customizable logarithmic bases and tick label factors.
[1891928] PercentageAxis
Useful for financial charts.
Here's an example what PercentageAxis can do:
http://sourceforge.net/tracker/download ... aid=772905
(You need to click the link. Does anybody know how to display an image directly? The
Short explanation: the arithmetic view (bottom image) could lead to the opinion, that the chart increased significantly during the last 10-15 days, but that's not the case - it rose, but not as much as the image demonstrates. In fact, the chart didn't increase much more compared to the former (November till December) - and the percentage scaling (top image) shows this much more accurate. Read on at
Price Scaling (StockCharts.com).[/url]
Last edited by
mhilpert on Tue Feb 12, 2008 4:57 pm, edited 7 times in total.
Java 11, JFreeChart 1.0.15, JFreeSVG 4.0
-
blutfink
- Posts: 2
- Joined: Wed Mar 15, 2006 10:54 am
- Location: Germany
Post
by blutfink » Wed Mar 15, 2006 11:57 am
It appears to me that this enhanced version of LogarithmicAxis will not work properly if the graphed values are below 1 (still positive though). In this case, the scale will be distorted. If I multiply my data to values above 1, the problem does not appear and the graphs are identical to those obtained with the original version of LogarithmicAxis.
See example below. The upper image is made with the enhanced version, the lower is made with the original version.
Code: Select all
LogarithmicAxis xAxis = new MyLogarithmicAxis("...");
Code: Select all
LogarithmicAxis xAxis = new LogarithmicAxis("...");
The data and the rest of the code are exactly the same.
-
blutfink
- Posts: 2
- Joined: Wed Mar 15, 2006 10:54 am
- Location: Germany
Post
by blutfink » Wed Mar 15, 2006 12:44 pm
As I see it now, this new LogarithmicAxis isn't designed to be used as a horizontal axis yet -- only as a vertical axis. Seems like I have to modify the original code myself.

-
JoeShmoe
- Posts: 2
- Joined: Thu Mar 30, 2006 4:59 pm
Post
by JoeShmoe » Mon Apr 03, 2006 5:41 pm
Hello,
How did you guys create another set of labels (top + bottom) for X-Axis? I need to do the same ...
Thanks,
Joe.
-
rantfoil
- Posts: 9
- Joined: Tue Dec 06, 2005 9:53 pm
Post
by rantfoil » Tue Oct 17, 2006 10:25 am
This logarithmic axis provided by mhilpert is fantastic.
One thing that I noticed with both JFreeChart is that it works well to chart any numbers below 1 as well, thanks to what is happening in adjustedLog10() method... or in mhilpert's fix, adjustedLog() which properly handles different bases.
But java2DToValue doesn't properly convert java2d values back to plot values because it assumes all values shown are greater than logBase.
Here's a method you can use in your versions that properly does conversion back...
Code: Select all
public double java2DToValue(double java2DValue, Rectangle2D plotArea, RectangleEdge edge) {
Range range = getRange();
double axisMin = switchedLog(range.getLowerBound());
double axisMax = switchedLog(range.getUpperBound());
double plotMin = 0.0;
double plotMax = 0.0;
if (RectangleEdge.isTopOrBottom(edge)) {
plotMin = plotArea.getX();
plotMax = plotArea.getMaxX();
}
else if (RectangleEdge.isLeftOrRight(edge)) {
plotMin = plotArea.getMaxY();
plotMax = plotArea.getMinY();
}
double retval;
if (isInverted()) {
retval = adjustedPow(axisMax
- ((java2DValue - plotMin) / (plotMax - plotMin)) * (axisMax - axisMin));
} else {
retval = adjustedPow(axisMin
+ ((java2DValue - plotMin) / (plotMax - plotMin)) * (axisMax - axisMin));
}
return retval;
}//translateJava2DtoValue()
public double adjustedPow(double val) {
boolean negFlag = false;
if (val < 0.0) {
negFlag = true;
val = -val;
}
double retval = 0;
if (val > 0 && val < 1) {
retval = (Math.pow(logBase, val+1) - logBase)/(logBase-1);
}
else if (val >= 1) {
retval = Math.pow(logBase, val);
}
return (negFlag) ? -retval : retval;
}
-
mhilpert
- Posts: 497
- Joined: Wed Apr 02, 2003 1:57 pm
- Location: Germany
Post
by mhilpert » Mon Dec 04, 2006 3:00 pm
@blutfink: sorry, I just needed the vertical axis, so far. The next version that I will update these days will have the corresponding refreshTicksHorizontal().
@rantfoil: I added your changes to my custom LogarithmicAxis. It didn't change my logarithmic charts but obviously java2DToValue() also needs the log base independent switchedLog() call instead of the standard switchedLog10().
I'm fighting with some tick label overlapping for a few of my logarithmic charts. I will upload a new version of both MyLogarithmicAxis and PercentageAxis soon with your changes incorporated.
If only David would finally integrate those classes in the standard API, I wouldn't have to fix many of those issues and change them for new JFreeChart versions due to changed APIs or (silently) changed implementations.

Java 11, JFreeChart 1.0.15, JFreeSVG 4.0
-
lgarcia3
- Posts: 43
- Joined: Thu Jul 21, 2005 4:00 pm
Post
by lgarcia3 » Thu Jan 18, 2007 11:18 pm
This question is for blutfink. How did you make your x axis come out like that? With all the values less than 0 showing up on the tick labels and the vertical lines for those values also there?
See, I have a log plot with values between 0.001 and 1 and I only get those two values on my plot and nothing else to show. My client wants to see values in bewteen to have some reference; but I cannot make it work. Any code would be helpful too.
Thanks!
-
evan
- Posts: 14
- Joined: Thu Feb 08, 2007 6:26 pm
Post
by evan » Tue Mar 13, 2007 2:49 am
mhilpert wrote:@blutfink: sorry, I just needed the vertical axis, so far. The next version that I will update these days will have the corresponding refreshTicksHorizontal().
@rantfoil: I added your changes to my custom LogarithmicAxis. It didn't change my logarithmic charts but obviously java2DToValue() also needs the log base independent switchedLog() call instead of the standard switchedLog10().
I'm fighting with some tick label overlapping for a few of my logarithmic charts. I will upload a new version of both MyLogarithmicAxis and PercentageAxis soon with your changes incorporated.
If only David would finally integrate those classes in the standard API, I wouldn't have to fix many of those issues and change them for new JFreeChart versions due to changed APIs or (silently) changed implementations.

Hi mphilpert,
Any update on the implementation of horizontal(i.e. domain) axis of this?
It's a bit annoying that LogarithmicAxis behaves differently for domain axis so that data can't be displayed with ticks as ...10^-1, 10^0, 10^1, 10^2....

Last edited by
evan on Tue Mar 13, 2007 3:39 pm, edited 1 time in total.
-
mhilpert
- Posts: 497
- Joined: Wed Apr 02, 2003 1:57 pm
- Location: Germany
Post
by mhilpert » Tue Mar 13, 2007 1:47 pm
I added a new version of MyLogarithmicAxis/PercentageAxis that overwrites refreshTicksHorizontal() which should do the trick. This is untested as I don't need this. If only it would be integrated into JFreeChart, as other people also like this functionality ...

Java 11, JFreeChart 1.0.15, JFreeSVG 4.0
-
evan
- Posts: 14
- Joined: Thu Feb 08, 2007 6:26 pm
Post
by evan » Tue Mar 13, 2007 3:57 pm
mhilpert wrote:I added a new version of MyLogarithmicAxis/PercentageAxis that overwrites refreshTicksHorizontal() which should do the trick. This is untested as I don't need this. If only it would be integrated into JFreeChart, as other people also like this functionality ...

Thanks mhilpert.
I've tried out your latest version of MyLogarithmicAxis, unfortunately, it still doesn't seem working for horizontal axis....

-
mhilpert
- Posts: 497
- Joined: Wed Apr 02, 2003 1:57 pm
- Location: Germany
Post
by mhilpert » Tue Feb 12, 2008 11:55 am
You can still achive the same by setting the vertical axis as logarithm axis, set orientation to horizontal, and place the y axis at right/bottom. The result will look like the x axis is the logarithm axis.
Java 11, JFreeChart 1.0.15, JFreeSVG 4.0
-
mhilpert
- Posts: 497
- Joined: Wed Apr 02, 2003 1:57 pm
- Location: Germany
Post
by mhilpert » Tue Feb 12, 2008 4:59 pm
I finally posted the axes as patches on sourceforge:
[1891921] Enhanced LogarithmicAxis
[1891928] PercentageAxis
In addition, both axes unifiy the two refreshTicksVertical()/refreshTicksHorizontal() and offer new superscript exponents for the tick labels.
Java 11, JFreeChart 1.0.15, JFreeSVG 4.0
-
mhilpert
- Posts: 497
- Joined: Wed Apr 02, 2003 1:57 pm
- Location: Germany
Post
by mhilpert » Mon Nov 05, 2012 2:32 pm
Java 11, JFreeChart 1.0.15, JFreeSVG 4.0