更改JasperReports图表的渲染

时间:2011-10-10 06:02:17

标签: charts jasper-reports

我正在尝试在JasperReports中更改图表的渲染类型。我已经正确设置了Chart Customizer属性,可以找到该类[并在调试时命中]但是,在呈现报表时不会进行所请求的更改。

JRChartCustomizer类是:

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);
    }
}

之前是否有人遇到此问题?

1 个答案:

答案 0 :(得分:1)

您需要调用plot.setRenderer(...)才能将渲染器实际应用于图表。

我的代码如下所示:

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);
}