Jump to content
  • Chart in Detail Band


    lucioamp
    Assigned User teodord
    CategoryBug report
    PriorityNormal
    ReproducibilityAlways
    ResolutionNo Change Required
    SeverityMajor
    StatusClosed

    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

    Hi,

     

    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,

    Teodor

     

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

    dataSource.add(...);

     

    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

    Hi,

     

    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.

    Teodor

     

    Link to comment
    Share on other sites


×
×
  • Create New...