Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#1124 Pie chart without legend does not respect order of colors provided by DrawingSupplier

1.0.x
open
nobody
5
2014-03-10
2014-03-07
Gábor Lipták
No

Maybe it is not a bug, but i consider this as a bug :)

I would suppose, that if I define a DrawingSupplier, then one color will be associated with each data item. This is not the case, as my example shows. See the code and the picture. It seems, that if one data item "does not paint anything" (including legend or text), then the color is not taken for it.

My humble guess is that not only pie chart is affected by this bug.

2 Attachments

Discussion

  • Gábor Lipták
    Gábor Lipták
    2014-03-07

    As a workaround I created this (sadly prevents using chartfactory):

    Custom Chart:

    public class CustomJFreeChart extends JFreeChart{
        public CustomJFreeChart(Plot plot) {
            super(plot);
        }
    
        public CustomJFreeChart(String title, Font titleFont, Plot plot,
                boolean createLegend) {
            super(title, titleFont, plot, createLegend);
        }
    
        public CustomJFreeChart(String title, Plot plot) {
            super(title, plot);
        }
    
        public synchronized void draw(Graphics2D g2, Rectangle2D chartArea, Point2D anchor, ChartRenderingInfo info) {
            if ( getPlot() instanceof CustomPiePlot ) {
                CustomPiePlot plot = (CustomPiePlot) getPlot();
                plot.lookupAllSectionPaints();
            }
            super.draw(g2, chartArea, anchor, info);
        }
    }
    

    Custom plot:

    public class CustomPiePlot extends PiePlot{
        private static final long serialVersionUID = 7120155232330958769L;
    
        public CustomPiePlot() {
            super();
        }
    
        public CustomPiePlot(PieDataset dataset) {
            super(dataset);
        }
    
        public void lookupAllSectionPaints() {
            @SuppressWarnings("rawtypes")
            List keys = getDataset().getKeys();
            for (Object keyObject : keys) {
                @SuppressWarnings("rawtypes")
                Comparable key = (Comparable) keyObject;
                lookupSectionPaint(key);
                lookupSectionOutlinePaint(key);
                lookupSectionOutlineStroke(key);
            }
        }
    }
    
     
    Last edit: Gábor Lipták 2014-03-07
  • David Gilbert
    David Gilbert
    2014-03-10

    I consider this a bug also, because it results in unexpected behavior. I don't know the best fix yet. It will impact other plot types, but it is more noticeable in the PiePlot because of the special handling of null and zero values.