0

I'm trying to change the render type of a Chart within JasperReports. I've got the Chart Customizer property set correctly, the class can be found [and hit when debugging] However the changes requested aren't made when the report is rendered.

The JRChartCustomizer class is:

public class PriceGraph implements JRChartCustomizer {

    public void customize(JFreeChart chart, JRChart jasperChart) {
        XYPlot plot = (XYPlot) chart.getPlot();
        XYItemRenderer renderer = plot.getRenderer();

        Shape shp = new Rectangle2D.Double(-0.5, -0.5, 1.0, 1.0);
        renderer.setBaseShape(shp);
        renderer.setSeriesPaint(0, Color.yellow);
        renderer.setBasePaint(Color.green);
    }
}

Has anyone hit this issue before?

monksy
  • 14,156
  • 17
  • 75
  • 124

1 Answers1

1

You need to call plot.setRenderer(...) to actually apply the renderer to the chart.

My code looks like this:

public void customize(JFreeChart chart, JRChart jasperChart) {
    XYPlot plot = (XYPlot) chart.getPlot();
    XYLineAndShapeRenderer renderer = plot.getRenderer();
    Shape shp = new Rectangle2D.Double(-0.5, -0.5, 1.0, 1.0);
    renderer.setSeriesShape(0, shp);
    renderer.setSeriesPaint(0, Color.yellow);
    renderer.setSeriesShapesVisible(0, Boolean.TRUE);
    renderer.setSeriesLinesVisible(0, Boolean.FALSE);
    plot.setRenderer(0, renderer);
}
GenericJon
  • 8,746
  • 4
  • 39
  • 50
  • Why is this accepted as the answer then? http://stackoverflow.com/questions/5140657/how-to-display-bar-value-for-each-bar-in-a-bar-graph – monksy Oct 10 '11 at 17:27
  • I added plot.setRenderer(renderer), and Its still generating the different shapes from: http://stackoverflow.com/questions/7701749/is-there-a-way-to-change-the-shape-size-in-a-jasperreports-chart – monksy Oct 11 '11 at 01:07
  • There's a few other differences between your code and mine. I use the concrete renderer class instead of the interface, I set the shape and the renderer for a particular series, and I call `setSeriesShapesVisible(...)` to make sure the shapes are shown. See the changes above. – GenericJon Oct 11 '11 at 08:14
  • The problem was each datapoint was configured to a new series. Changing that fixed the issue with the custom shape etc. Also afterward the code didn't need the setRenderer – monksy Oct 11 '11 at 09:42