0

I am trying to use the customizer class BarRenderer from jFree charts to customize a bar chart, I have added the jar to the classpath and added the class to the customizer class section of the Bar Chart properties as org.jfree.chart.renderer.category.BarRenderer and I keep getting the error:

net.sf.jasperreports.engine.JRRuntimeException: Could not create chart customizer instance.
Caused by: java.lang.ClassCastException: org.jfree.chart.renderer.category.BarRenderer cannot be cast to net.sf.jasperreports.engine.JRChartCustomizer

Is there something I am missing or forgot to do here, any help to get this running would be much appreciated

Alex K
  • 22,315
  • 19
  • 108
  • 236

1 Answers1

0

A customizer and a renderer are two different animals: the renderer is responsible for painting a part of the chart while the customizer lets you customize it.

What you need to do is create a class that extends JRChartCustomizer and in the customize method set the BarRenderer:

public class MyCustomizer extends JRAbstractChartCustomizer {
    public void customize(JFreeChart chart, JRChart jasperChart) {
        if (chart.getPlot() instanceof CategoryPlot) {
            CategoryPlot plot = (CategoryPlot) chart.getPlot();
            plot.setRenderer(new BarRenderer());
        }
    }
}

Then in your design you need to set the customizer to MyCustomizer and make sure that your class is in the classpath

Guillaume
  • 14,306
  • 3
  • 43
  • 40