How to fill new page with same type of data

I am using JasperReports and I would like to generate charts for different objects from same POJO class. POJO Class looks like below:

 

public class POJOClass{
private Double value;
private long timestamp; //constructor+getters

What do I want to do?

  • In first step I would like to fill chart from value of first object.

  • Then I would like to add next page and go into second step of loop, get from database next object and fill chart in 2nd page.

I am using same POJO however both objects has different value. The problem is that I can fill only one page.

InputStream jasperStream = this.getClass().getResourceAsStream("generate.jrxml");
JasperDesign design = JRXmlLoader.load(jasperStream);
for (int i = 0; i < size; i++) {
        List<POJOClass> pojoDescribtions= new ArrayList<>(); //add some result into List
        JRDataSource jrDataSource = new JRBeanCollectionDataSource(pojoDescribtions);
        parameterMap.put("datasource", jrDataSource);
 
        jasperPrint = JasperFillManager.fillReport(report, parameterMap, jrDataSource);
 
}

It always create chart for 2nd step and I do not know how to get also for the first one.

tom_40's picture
3
Joined: Apr 24 2018 - 12:38am
Last seen: 5 years 4 months ago

1 Answer:

Try

List<POJOClass> pojoDescribtions= new ArrayList<>();
for (int i = 0; i < size; i++)  {
  //add some result into List
}
JRDataSource jrDataSource = new JRBeanCollectionDataSource(pojoDescribtions);   
parameterMap.put("datasource", jrDataSource);
jasperPrint = JasperFillManager.fillReport(report, parameterMap, jrDataSource);

Also make sure your chart is placed in the detail band of the report.

shertage's picture
22160
Joined: Sep 26 2006 - 8:06pm
Last seen: 2 months 2 weeks ago
Feedback