JasperReports supports a large number of built-in charts created using the popular open source library JFreeChart. Chart types include Pie, Bar, Stacked Bar, Line, Area, Bubble, Gantt, Thermometer and Meter. In this tutorial we will learn how to add a multi-series chart to a report, using the datasource created in the tutorial Creation of a Dataset. With the report opened, drag and drop it from the palette into the Summary section:
After the chart is placed the creation wizard will appear. On the first step select a "Pie Chart", to have something different from the previous tutorial, and hit Next. In the following step find the field named "Dataset", normally with the value "[MainDataset]". You must change this value to "GroupData" (to create this dataset follow the create a dataset tutorial), so the chart will use the new dataset, as in the image below:
Now you have to configure the series of the chart, click the button with three dots on the right of the series combo, a new dialog will appear:
In this dialog you can define the series of the chart, even using an expression. Delete the default item by selecting it and clicking the "Delete" button, and then press the "Add" button. The expression editor will be opened, and here select the item "Fields" and double click on the item "SHIPCITY", finally click "Finish" to close the expression editor:
Now you will return to the dialog of the series, here just hit "Ok" to go to the chart configuration. Configure it as shown in the following image:
The chart configuration is finished, click the button "Finish" to complete the wizard. The only thing to do is give to the chart all the avaiable space in its band, so right click on the chart, select "Size to Container" and then "Fit Both". Doing this the chart will fill the Summary band, now go in the "Preview" tab to compile the report and go to the last page to see the chart: