range gridlines for secondary axis workaround

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
alsw-2000
Posts: 16
Joined: Thu May 22, 2003 12:53 pm

range gridlines for secondary axis workaround

Post by alsw-2000 » Tue Feb 03, 2004 8:45 am

I know that gridlines are only drawn for the ticks on the primary axis. However my customer insist to draw gridlines for both primary and secondary axises.

I am trying to make the gridlines looks like drawn for both ticks by increasing the range of the axis with smaller calculateVisibleTickCount(), so that both axis has the same number of tick count and the gridlines seems drawn for both axis.

But I found that the calculateVisibleTickCount() function is returning the wrong value and the axis.getTickUnit().getSize() function just return 1 and which is not the real tick size show on the chart.

It seems that the setAutoTickUnitSelection function haven't initialize those values when I get it.
when is the plot calculate the tick size and tick count value?
how can I get the real tick size and tick count value?

All I want is to draw gridline for both primary and secondary axises, any other suggestion or workaround is welcome

Regards,
Andy

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

Post by david.gilbert » Tue Feb 03, 2004 10:31 am

I would modify the XYPlot class. In the draw() method, you will find this line:

Code: Select all

Map axisStateMap = drawAxes(g2, area, dataArea);
It draws all the axes and returns a state object for each one (among other things, the state object holds a list of the tick values for the axis). Later in the same method, the gridlines for the primary range axis are drawn:

Code: Select all

        AxisState rangeAxisState = (AxisState) axisStateMap.get(getRangeAxis());
        if (rangeAxisState == null) {
            if (parentState != null) {
                rangeAxisState = (AxisState) parentState.getSharedAxisStates().get(
                    getRangeAxis());
            }
        }
        if (rangeAxisState != null) {
            drawRangeTickBands(g2, dataArea, rangeAxisState.getTicks());
            drawRangeGridlines(g2, dataArea, rangeAxisState.getTicks());
        }
It wouldn't be too difficult to add something to draw gridlines for the secondary axis (or axes) in the same way.
David Gilbert
JFreeChart Project Leader

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

Locked