AbstractRenderer.setPaint() deprecated - but has to be used!

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
mhilpert
Posts: 497
Joined: Wed Apr 02, 2003 1:57 pm
Location: Germany

AbstractRenderer.setPaint() deprecated - but has to be used!

Post by mhilpert » Tue Jun 18, 2013 2:59 pm

Methid AbstractRenderer.setPaint(Paint paint) is deprecated:
@deprecated This method should no longer be used (as of version 1.0.6).
* It is sufficient to rely on {@link #setSeriesPaint(int, Paint)} and
* {@link #setBasePaint(Paint)}.
I tried the replacement methods, but they don't work! Example:

Code: Select all

    /**
     * Min/Max chart.
     * 
     * @return JFreeChart.
     */
    private final JFreeChart testMinMaxChart() {
        JFreeChart result = null;
        
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.addValue(1.0, "First", "C1");
        dataset.addValue(4.0, "First", "C2");
        dataset.addValue(3.0, "First", "C3");
        dataset.addValue(5.0, "First", "C4");
        dataset.addValue(5.0, "First", "C5");
        dataset.addValue(7.0, "First", "C6");
        dataset.addValue(7.0, "First", "C7");
        dataset.addValue(8.0, "First", "C8");
        dataset.addValue(5.0, "Second", "C1");
        dataset.addValue(7.0, "Second", "C2");
        dataset.addValue(6.0, "Second", "C3");
        dataset.addValue(8.0, "Second", "C4");
        dataset.addValue(4.0, "Second", "C5");
        dataset.addValue(4.0, "Second", "C6");
        dataset.addValue(2.0, "Second", "C7");
        dataset.addValue(1.0, "Second", "C8");
        dataset.addValue(4.0, "Third", "C1");
        dataset.addValue(3.0, "Third", "C2");
        dataset.addValue(2.0, "Third", "C3");
        dataset.addValue(3.0, "Third", "C4");
        dataset.addValue(6.0, "Third", "C5");
        dataset.addValue(3.0, "Third", "C6");
        dataset.addValue(4.0, "Third", "C7");
        dataset.addValue(3.0, "Third", "C8");
        
        result = ChartFactory.createBarChart(
                "Min/Max Category Plot",  // chart title
                "Category",               // domain axis label
                "Value",                  // range axis label
                dataset,                  // data
                PlotOrientation.VERTICAL,
                true,                     // include legend
                false,                     // tooltips
                false                     // urls
            );

            CategoryPlot plot = (CategoryPlot) result.getPlot();
            //plot.setRangePannable(true);
            MinMaxCategoryRenderer renderer = new MinMaxCategoryRenderer();
            renderer.setDrawLines(false);
            final ImageIcon icon = new ImageIcon("H:/MinMaxIcon_Empty.png");
            renderer.setMinIcon(icon);
            renderer.setMaxIcon(icon);
//            renderer.setObjectIcon(icon);
            
            
            renderer.setPaint(Color.black);
//            renderer.setSeriesPaint(0, Color.black);
//            renderer.setSeriesPaint(1, Color.black);
//            renderer.setSeriesPaint(2, Color.black);
//            renderer.setBasePaint(Color.black);
            
    
            plot.setRenderer(renderer);
            
            ChartUtilities.applyCurrentTheme(result);

        return result;
    }//testMinMaxChart()

This should paint all lines of the Min/Max plot in black. If I replace setPaint() by the 4 methods below - they are not black anymore!!!
Java 11, JFreeChart 1.0.15, JFreeSVG 4.0

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: AbstractRenderer.setPaint() deprecated - but has to be u

Post by paradoxoff » Tue Jun 18, 2013 4:45 pm

In your code, you are probably overwriting your user defined series paints with defaults that are selected by the current chart theme.
When you are calling AbstractRenderer.setPaint(Paint thePaint) with a non-null argument, you are setting a default that will be returned from lookupSeriesPaint(int series) and getItemPaint(int series, int item), internally, the latter method is calling the former. The setttings for the series paints (regardless of whether you have defined them manually, or whether you rely on the autopopulate feature, or whether you let the chart theme define the series) are then ignored.

mhilpert
Posts: 497
Joined: Wed Apr 02, 2003 1:57 pm
Location: Germany

Re: AbstractRenderer.setPaint() deprecated - but has to be u

Post by mhilpert » Mon Jun 24, 2013 4:24 pm

I guess the problems are the setMinIcon(), set MaxIcon(). When I call these methods, the colors just go crazy! Also the lines: they have different angles and what's worse: when I resize the Frame the chart gets currupted everytime in another way...
Java 11, JFreeChart 1.0.15, JFreeSVG 4.0

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: AbstractRenderer.setPaint() deprecated - but has to be u

Post by paradoxoff » Tue Jun 25, 2013 8:50 pm

Are you still talking about the observation that the colors are not black when you do not call setPaint() on the renderer or have you encountered new issues?
All in all, your error descripotion is a bit vague.
I had a look at the source, and I couldn't see anything that could lead to side effects if you are using custom icons for the minIcons and the maxIcons.

mhilpert
Posts: 497
Joined: Wed Apr 02, 2003 1:57 pm
Location: Germany

Re: AbstractRenderer.setPaint() deprecated - but has to be u

Post by mhilpert » Tue Jun 25, 2013 10:21 pm

Java 11, JFreeChart 1.0.15, JFreeSVG 4.0

Locked