Creating Excel reports containing charts is not difficult with jXLS. Mainly it is possible because Jakarta POI attempts to keep existing records intact as far as possible.

Basic Chart Sample

To create a chart in Excel we have to set source data range. Here we assume that these source data takes up a fixed number of rows and all data for the rows are contained in some collection. To setup this with jXLS we should use fixed size collection feature. Let's look at XLS template screenshot for setting up Payment charts for a list of employees

Screenshot of Employee Payment Charts XLS Template


You can see that source data list employee is setup for fixed size collection export. Here is the source code snippet to run the sample

				        List staff = new ArrayList();
				        staff.add(new Employee("Derek", 35, 3000, 0.30));
				        staff.add(new Employee("Elsa", 28, 1500, 0.15));
				        staff.add(new Employee("Oleg", 32, 2300, 0.25));
				        staff.add(new Employee("Neil", 34, 2500, 0.00));
				        staff.add(new Employee("Maria", 34, 1700, 0.15));
				        staff.add(new Employee("John", 35, 2800, 0.20));
				        staff.add(new Employee("Leonid", 29, 1700, 0.20));
				        Map beans = new HashMap();
				        beans.put("employee", staff);
				        XLSTransformer transformer = new XLSTransformer();
				        transformer.transformXLS(templateFileName, beans, destFileName);

You can see that employee list is marked as fixed size collection .

Here is the output

Screenshot of Employee Payment Charts XLS Output


Dynamic Rows Chart Sample

It is possible to create a chart even if the number of source data rows is dynamic. Check the following articles to understand the approach to this