Possible bug in CategoryPlot.setRangeAxis

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
astenwick
Posts: 13
Joined: Tue Apr 13, 2004 8:03 pm
Location: Seattle

Possible bug in CategoryPlot.setRangeAxis

Post by astenwick » Fri May 21, 2004 11:50 pm

I'm trying to set the RangeAxis in my CategoryPlot class, after I've previously initialized it to null (because I don't know if there's going to be a shared RangeAxis with another plot yet). But when I call setRangeAxis it causes a null pointer exception. Here's stack trace:

Code: Select all

java.lang.NullPointerException
	at com.eoscene.cdds.chart.plot.CategorySubplot.getRangeAxis(CategorySubplot.java:55)
	at org.jfree.chart.plot.CategoryPlot.getDataRange(CategoryPlot.java:2430)
	at org.jfree.chart.axis.NumberAxis.autoAdjustRange(NumberAxis.java:350)
	at org.jfree.chart.axis.NumberAxis.configure(NumberAxis.java:333)
	at org.jfree.chart.axis.Axis.setPlot(Axis.java:686)
	at org.jfree.chart.plot.CategoryPlot.setRangeAxis(CategoryPlot.java:708)
	at com.eoscene.cdds.chart.builder.AssetTypeChartBuilder.getPlot(AssetTypeChartBuilder.java:103)
	at com.eoscene.cdds.chart.builder.AssetTypeChartBuilder.getChart(AssetTypeChartBuilder.java:81)
	at com.eoscene.cdds.chart.builder.AssetTypeChartBuilder.displayChart(AssetTypeChartBuilder.java:63)
	at com.eoscene.cdds.chart.builder.OptionsChartBuilder.main(OptionsChartBuilder.java:169)
I beleive the problem is that the method eventually calls getRangeAxis which hasn't yet been set in the method. An appropriate solution would be to move the call to axis.setPlot after you have already set the rangeAxis to the incoming variable.

Current implementation:

Code: Select all

    public void setRangeAxis(ValueAxis axis) {

        if (axis != null) {
            axis.setPlot(this);
        }

        // plot is likely registered as a listener with the existing axis...
        if (this.rangeAxis != null) {
            this.rangeAxis.removeChangeListener(this);
        }

        this.rangeAxis = axis;
        if (axis != null) {
            axis.configure();
            axis.addChangeListener(this);
        }
        notifyListeners(new PlotChangeEvent(this));

    }
Proposed:

Code: Select all

    public void setRangeAxis(ValueAxis axis) {

        // plot is likely registered as a listener with the existing axis...
        if (this.rangeAxis != null) {
            this.rangeAxis.removeChangeListener(this);
        }

        this.rangeAxis = axis;

        if (axis != null) {
            axis.setPlot(this);
            axis.configure();
            axis.addChangeListener(this);
        }
        notifyListeners(new PlotChangeEvent(this));

    }

astenwick
Posts: 13
Joined: Tue Apr 13, 2004 8:03 pm
Location: Seattle

Post by astenwick » Sat May 22, 2004 12:23 am

Nevermind - I guess the problem was with my CategorySubplot subclass.

sorry!

Locked