Issue with LogAxis and minor grid lines

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
wiedenig
Posts: 3
Joined: Tue Nov 07, 2017 12:55 pm
antibot: No, of course not.

Issue with LogAxis and minor grid lines

Post by wiedenig » Tue Nov 07, 2017 1:09 pm

Hi,
I think there is an error with LogAxis and minor grid lines.
The problem accurs when I use LogAxis (Domain or Range does not matter) and the minor grid lines are displayed.
There should be 8 minor lines between the mayor lines - but there are 9.
e.g. between 10^0 (=1) and 10^1 (=10) there should be 8 minor lines for 2,3,4,5,6,7,8,9
but there are 9...

When I use LogarithmicAxis it is correct.
My problem is that I want to use LogAxis because it's easier to get the tick marks right.
Any chance this will be fixed?
Thanks,
Thomas

wiedenig
Posts: 3
Joined: Tue Nov 07, 2017 12:55 pm
antibot: No, of course not.

Re: Issue with LogAxis and minor grid lines

Post by wiedenig » Wed Nov 08, 2017 4:48 pm

Hi,
Nobody experienced the same problem?
Here's a picture:
Image
Thanks,
Thomas

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Issue with LogAxis and minor grid lines

Post by paradoxoff » Thu Nov 09, 2017 4:43 pm

Looks like a classical bug to me.
In the current version of JFreeChart, the LogAxis calculates the minor ticks in a way that seems to be identical to that of a NumberAxis, i.e. with 1, 3, 4, or 9 minor tick lines between major tick lines.
In an earlier version, the minor tick count could be explicitly set for a ValueAxis, and the default for a LogAxis was 9 (corresponding to 9 "regions" between major tick marks, which are separated from each other by 8 minor tick lines).

wiedenig
Posts: 3
Joined: Tue Nov 07, 2017 12:55 pm
antibot: No, of course not.

Re: Issue with LogAxis and minor grid lines

Post by wiedenig » Sat Nov 11, 2017 9:08 pm

Hi,
I found a solution for above problem:
  • download the source file of LogAxis.java
  • change line number 144 (replace 10 with 9) and include the file in your project (don't forget to include the missing imports)
  • set the axis auto tick unit selection to false: axis.setAutoTickUnitSelection(false);
That's all!
Thomas

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

Re: Issue with LogAxis and minor grid lines

Post by david.gilbert » Mon Nov 13, 2017 9:30 pm

The auto tick unit selection can probably be fixed by changing the code here:

Code: Select all

    public LogAxis(String label) {
        super(label, new NumberTickUnitSource());
        setDefaultAutoRange(new Range(0.01, 1.0));
        this.tickUnit = new NumberTickUnit(1.0, new DecimalFormat("0.#"), 9);
    }
In the call to super(), the NumberTickUnitSource instance assumes 10 minor tick intervals, whereas we want 9 I guess. The initial tickUnit I already changed in the code above.
David Gilbert
JFreeChart Project Leader

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

Locked