How to Pass the Java List<Map> or List<?> as Chart DataSource in the JRXML Based Reports?

Table of Contents 

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.


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:

In sample report we use:

new (
        ["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