Logarithmic Axis - How can I use exponential numbers

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Alfi@leman
Posts: 3
Joined: Mon Jul 24, 2006 11:01 pm

Logarithmic Axis - How can I use exponential numbers

Post by Alfi@leman » Sat Jul 29, 2006 8:40 pm

Hi,

I am working on a line chart that has logarithmic axis for both x and y. The data range is over several decades and I would like exponential numbers on the axis.

Example: 0.00000001 doesn't look good. I would like to see 1.0e-9 or 10-9 or something like that.

Does anyone know how to do this? If log axis are available, exp. notation for numbers should also be available.

Thanks

Alfi

SeanMcCrohan
Posts: 18
Joined: Thu May 11, 2006 11:22 pm

Post by SeanMcCrohan » Tue Aug 01, 2006 8:27 pm

You want something like:

Code: Select all

    	
LogarithmicAxis myLogAxis = new LogarithmicAxis("Test");
NumberFormat numFormat = new DecimalFormat("0.###E0");
myLogAxis.setNumberFormatOverride(numFormat);
This is also handy when using a DateAxis - the default date format for a DateAxis gets messed up if, in a chart with a multi-day range, you zoom down to a narrow timerange and then back. It starts off including the date and time, drops the date when you zoom in, and doesn't add it back when you zoom back out. If you set your own DateFormat, that doesn't happen.

Alfi@leman
Posts: 3
Joined: Mon Jul 24, 2006 11:01 pm

Post by Alfi@leman » Wed Aug 02, 2006 8:43 pm

Thanks. That works but only with numbers greater/equal 1. Numbers smaller 1 are not changed. This looks funny. My code is slightly different, but this should make no difference ?

Code: Select all

NumberAxis domainAxis = new LogarithmicAxis("xxx");
NumberAxis rangeAxis = new LogarithmicAxis("YYYY");
...
NumberFormat numFormat = new DecimalFormat("0.###E0");
rangeAxis.setNumberFormatOverride(numFormat);
Any idea what this could be? In my opinion this should work for all numbers or not at all.

SeanMcCrohan
Posts: 18
Joined: Thu May 11, 2006 11:22 pm

Post by SeanMcCrohan » Wed Aug 02, 2006 9:42 pm

I'm not sure; my log data doesn't have any fractional values, so I hadn't run into that before. I'm not actually even sure how to get gridlines for sub-1 values to show up, as changing the tick unit doesn't seem to do it.

However, while looking for that, I did discover something else that might work for you: logAxis.setLog10TickLabelsFlag(true)

It sets the tick labels to 10^X format, without messing with an explicit NumberFormat.

Alfi@leman
Posts: 3
Joined: Mon Jul 24, 2006 11:01 pm

Post by Alfi@leman » Thu Aug 03, 2006 2:06 pm

The setLog10TickLabelsFlag(true) works over the complete range. Thanks.

I ran a small test with the DecimalFormat:

Code: Select all

double[] test = {123.23,12.9,1.543,0.986,0.002345,0.0000005678,-0.2348,-23.9};
DecimalFormat dec = new DecimalFormat ("0.###E0");
for (int n=0; n<test.length; n++) {
           System.out.println(dec.format(test[n]));  }

Output:

1.232E2
1.29E1
1.543E0
9.86E-1
2.345E-3
5.678E-7
-2.348E-1
-2.39E1
This works perfectly, but it does not with the line chart.

hugues
Posts: 18
Joined: Tue Jul 04, 2006 8:59 am
Contact:

Re: Logarithmic Axis - How can I use exponential numbers

Post by hugues » Mon Sep 18, 2006 10:24 am

Alfi@leman wrote:Example: 0.00000001 doesn't look good. I would like to see 1.0e-9 or 10-9 or something like that.
Alfi
I also have plots will low values, and with logarithmic axis or not, under 1e-7 I only have ONE value in the axis scale which is a problem.
SAMTECH, Integrating CAE towards Professional Solutions : www.samcef.com

Locked