Symbol axis in colorlegend

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
fvanleeu
Posts: 1
Joined: Mon Jan 11, 2016 10:52 am
antibot: No, of course not.

Symbol axis in colorlegend

Post by fvanleeu » Mon Jan 11, 2016 11:10 am

For a number of charts I required a colour legend with symbols rather than numbers. Using the SymbolAxis class in JFreeChart 1.0.19 (but also in earlier versions), I obtained a display of the legend, but a zero-pointer error prevented the actual chart to be displayed. Doing the same with NumberAxis both the colour legend and the chart were displayed. After some digging I found that the cause of the problem was in the "draw" function in SymbolAxis. I copied the code from the equivalent function of NumberAxis into SymbolAxis to replace the original code, and now it all works, I have both the chart and the colour legend with symbols displayed:

Code: Select all

    @Override
    public AxisState draw(Graphics2D g2, double cursor, Rectangle2D plotArea,
            Rectangle2D dataArea, RectangleEdge edge, 
            PlotRenderingInfo plotState) {

        AxisState state;
        // if the axis is not visible, don't draw it...
        if (!isVisible()) {
            state = new AxisState(cursor);
            // even though the axis is not visible, we need ticks for the
            // gridlines...
            List ticks = refreshTicks(g2, state, dataArea, edge);
            state.setTicks(ticks);
            return state;
        }

        // draw the tick marks and labels...
        state = drawTickMarksAndLabels(g2, cursor, plotArea, dataArea, edge);

        if (getAttributedLabel() != null) {
            state = drawAttributedLabel(getAttributedLabel(), g2, plotArea, 
                    dataArea, edge, state);
            
        } else {
            state = drawLabel(getLabel(), g2, plotArea, dataArea, edge, state);
        }
        createAndAddEntity(cursor, state, dataArea, edge, plotState);
        return state;
//
//        AxisState info = new AxisState(cursor);
//        if (isVisible()) {
//            info = super.draw(g2, cursor, plotArea, dataArea, edge, plotState);
//        }
//        if (this.gridBandsVisible) {
//            drawGridBands(g2, plotArea, dataArea, edge, info.getTicks());
//        }
//        return info;

    }


It would be nice if this, or an equivalent, adjustment to the code could be applied in a next release.

Locked