Jump to content
  • Chart in Detail Band

    Assigned User teodord
    CategoryBug report
    ResolutionNo Change Required

    When a chart is placed in the detail band and the datasource used in the chart is populated dynamically by a collection of java beans (sent by a java application using JRBeanCollectionDataSource class), the chart data is only displayed in the first record.


    Debugging the JasperReport source code, the collection of java beans is handled by it's iterator and the collection is fully read to populate the chart data for the first record. Since jasper is using an iterator, when the next record of the report is processed the iterator is still pointed to it's end. It seems the method JRBeanCollectionDataSource.moveFirst() should be called as a new record is processed.


    As a temporarily fix, the code below was put in the java application. The class JRFillDatasetRun was overridden to have the code below after a datasource is initialized:


    if (dataset.dataSource instanceof JRRewindableDataSource) {

    ((JRRewindableDataSource) dataset.dataSource).moveFirst();


    User Feedback

    Recommended Comments



    What you describe is not a bug, but rather a wrong usage of the JRBeanCollectionDataSource.

    You have not posted any files so that we could tell you what is wrong with them. Please do, if you want to have your problem fixed.


    Thank you,



    Link to comment
    Share on other sites

    Hi Teodor,


    I attached the jrxml file.

    I defined a datasource parameter (Chart1Datasource) in the report and I put the code below in the java application. The "datasource" variable is the main datasource of the report (not used by the chart).


    List dataSource = new ArrayList();



    HashMap reportParams = new HashMap();

    List chart1Datasource = ...;

    reportParams.put("Chart1Datasource", new JRBeanCollectionDataSource(chart1Datasource));


    URL reportFile = Thread.currentThread().getContextClassLoader().

    getResource(jasperBasePath + "Relatorio_analise_resultados.jrxml");


    JasperPrint print = JasperFillManager.fillReport(reportFile.openStream(), reportParams, new JRBeanCollectionDataSource(dataSource));

    return JasperExportManager.exportReportToPdf(print);


    Thank you

    Lúcio Pereira

    Link to comment
    Share on other sites



    Do not pass JRBeanCollectionDataSource instances as parameters, but rather pass the raw Collection object. You'd be wrapping the collection in a data source instance in the .


    This way a new data source is created every time the chart is run, discarding previous data source instances which have reached the last record.


    This is the way to do it. There is no point in calling moveFirst. Just create another data source every time.


    I hope this helps.



    Link to comment
    Share on other sites

  • Create New...