Jump to content
Changes to the Jaspersoft community edition download ×
  • How to Pass the Java List<Map> or List<?> as Chart DataSource in the JRXML Based Reports?


    asimkin
    • Features: Charts, Custom Data Sources, Data Sources Version: v6.3

    Issue Description

    We have created a jrxml based report and deployed at the Jasper Server. A chart in a report, which is filled data by executing the query in the Sub DataSet.

     

    Instead of executing the query, we need to pass the java List<Map> or List<?> as datasource to the chart.

    We can call the java class from jrxml based report (Have called the java class in a textField). But, we need to pass this collection to a chart.

     

    How to configure the jrxml which support the java collection as datasource to a chart? Please give us a sample report & provide steps to try it in our end.


    Resolution

    What you need to do is to wrap the List of maps/objects in a JRMapCollectionDataSource/JRBeanCollectionDataSource instance.

     

    Please find attached a report which uses a JRMapCollectionDataSource with hardcoded values (written as Groovy literals) to fill a chart.

    The main idea is to specify property JRDatasource expression, please find attached printscreen:

    JSS_ListAsChartDatasource.png.a1fb05ff925a660d864a593dfc9192c3.png

    In sample report we use:

    new net.sf.jasperreports.engine.data.JRMapCollectionDataSource (
        [
            ["key" : "a", val: 5],
            ["key" : "b", val: 8], 
            ["key" : "c", val: 3]
        ]
    )
    

    but you can modify it per your requirements.

    The same idea can be used if you need to pass List of maps/objects to Table component.


    Ref. Case 01454782

    JSS_ListAsChartDatasource.png.d1e08a24d8e3aa5121471ca085e05775.png

    highchartschart_2.jrxml


    User Feedback

    Recommended Comments

    There are no comments to display.



    Guest
    This is now closed for further comments

×
×
  • Create New...