0

I have created a report (which uses line chart) in iReport and using JasperReports libraries to print the report in my web application.

I am using the customizer class to customize few options in the line chart. Now because that class is common across all the charts.

Now some of my charts has 2 series and someone them has only 1.

Is there any way I can know the no of series in my class.

The below is the sample class. I want to set their shape for all the series to the same.

public class LineChartCustomizer implements JRChartCustomizer  {

    private static Log  log = LogFactory.getLog(LineChartCustomizer.class);

    @Override
    public void customize(JFreeChart jFreeChart, JRChart jrChart) {

        CategoryPlot plot = jFreeChart.getCategoryPlot();

        LineAndShapeRenderer renderer = new LineAndShapeRenderer();                        

        renderer.setSeriesShape(0, ShapeUtilities.createDiamond(1F));
        //Need help in above to loop through total no of series instead of hard coding to 0

        //This is so that the value of X axis starts from 0 and does not leave any space
        plot.getDomainAxis().setLowerMargin(0.01);
        plot.getDomainAxis().setUpperMargin(0.01);   

        plot.setRenderer(renderer);
    }
}
4

1 回答 1

2

您可以通过调用获取系列总数:

jFreeChart.getXYPlot().getDataset().getSeriesCount()

使用它来修改所有系列应该很简单。

int seriesCount = jFreeChart.getXYPlot().getDataset().getSeriesCount()
for (int i = 0; i < seriesCount; i++) {
    renderer.setSeriesShape(i, ShapeUtilities.createDiamond(1F));
}
于 2013-09-06T11:21:06.427 回答