0
votes

I'm using JFreeChart to create XYLineCharts with a "logarithmic" y-axis but am facing a bug that I just do not seem to be able to solve.

My values are very low in some cases (in one such case, the y-axis values range between 4.5e-8 to 1.7112). I plot these values on a XYLineChart using a Logarithmic Axis for the y-axis (and using LogAxis.createLogTickUnits(Locale.ENGLISH) and .setExpTickLabelsFlag(true) on the y-axis to create the exponential tick units). I set my range's bounds from 4.5e-8 to 1.712 and can see the points clearly, even though the chart shows just 1 value on the y-axis: 1e0.

This is okay but when I zoom further into the chart, the tick labels on the y-axis automatically disappear. This also happens in charts using the NumberAxis if I zoom too much into the y-axis value. Basically, if the difference in the y-axis values become very low (and over 8 decimal places), the labels disappear.

How do I override the zoom() method in JFreeChart so as to force it to show tick labels/ names whenever a chart is zoomed.

If anyone has any suggestions or a solution, please let me know as soon as possible as I need to implement this ASAP.

Thanks.

2
please does anyone have any suggestions ? I'm stuck with this JFreeChart bug and cannot think of a way to fix it...Ajit Singh

2 Answers

0
votes

Zoom event is triggered in two cases: mouse wheel and popup menu command. In both cases, the "zoom*" methods of "ChartPanel" (zoomInBoth, zoomInDomain, zoomInRange, etc.) will be called, so according to your need, you can override these methods.

I don't think it is a good idea to override these methods. Maybe there are some configurations about axises' attributes which you can change so that tick labels/names won't disappear after zooming. You can consult the source code.

0
votes

I know it's been a while but I had the same problem because when zooming in, the tick unit becomes too big and no labels are displayed.

What I did is listenning for a AxisChange and compute a new tick unit then set it to the axis.

Here is an example:

chart.getXYPlot().getDomainAxis().addChangeListener(new AxisChangeListener() {
        @Override
        public void axisChanged(AxisChangeEvent e) {
            // TODO Auto-generated method stub
            Date lowerB = ((DateAxis)e.getAxis()).getMinimumDate();
            Date upperB = ((DateAxis)e.getAxis()).getMaximumDate();
            setTick(((DateAxis)e.getAxis()),calculateTick(lowerB,upperB));
        }
    });

Be carefull in the setTick method to check if the tick has changed otherwise it will be a infinite loop due to the event.This could maybe be resolve by using a "zoom listener" and not a AxiChanged Listenner but I did not find any.