Using Charts in JasperReports

By: MakeItSimple. Viewed: 153344 times  Printer Friendly Format    


JasperReports now has built-in support for charts. There is a new chart component ready to use like we already had images, text fields, subreports and other elements.

This greatly simplifies the way charts are included inside reports, because previously the user had to completely rely on scriptlets in order to gather the chart data and render the chart using an image element in the report template.  

Now with the new chart component, the user only has to make the desired visual settings to it and define the expressions that will help the engine built-up the chart dataset in a incremental fashion during the iteration through the report data source.  

When including and configuring a chart component, there are three entities involved:  

- the overall chart component;  
- the chart dataset (groups chart data related settings);10.0pt;font-family:Verdana; color:black">  
- the chart plot (groups visual settings related to the way the chart items are rendered);  

JasperReports currently supports the following types of charts:10.0pt; font-family:Verdana;color:black">  
Pie, Pie 3D, Bar, Bar 3D, XY Bar, Stacked Bar, Stacked Bar 3D, Line, XY Line, Area, XY Area, Scatter Plot, Bubble, Time series, High Low Open Close, Candlestick.  

These types of charts use several types of datasets (each type of chart works with certain types of datasets): Pie Dataset, Category Dataset, XY Dataset, Time Series, Time Period Values, XYZ Dataset, High Low Dataset.10.0pt; font-family:Verdana;color:black">  

For all charts we can configure the following:

- border around all sides  
- background color  
- title  
- title position (top, left, bottom, right)  
- title font  
- title color  
- subtitle  
- subtitle color  
- subtitle font  
- show/hide legend  
- plot area background color  
- plot area background transparency (alpha)10.0pt;font-family:Verdana; color:black">  
- plot area foreground transparency (alpha)10.0pt;font-family:Verdana; color:black">  
- plot orientation (vertical, horizontal)  
- axis labels

For all datasets we can configure:

- increment type (detail, column, page, group, report)10.0pt;font-family:Verdana; color:black">  
- increment group  
- reset type (none, column, page, group, report)10.0pt;font-family:Verdana; color:black">  
- reset group

Specific settings by chart type:

Pie 3D

- depth factor

Bar, XY Bar, Stacked Bar

- hide/show labels  
- hide/show tick marks  
- hide/show tick labels

Bar 3D, Stacked Bar 3D

- hide/show labels  
- x offset (3D effect)  
- y offset (3D effect)

Line, XY Line, Scatter Plot, Time series

- hide/show lines  
- hide/show shapes

Bubble

- scale type (both axes, domain axis, range axis)10.0pt;font-family:Verdana; color:black">

High Low Open Close

- hide/show close ticks  
- hide/show open ticks

Candlestick

- hide/show volume

JasperReports uses the JFreeChart library to render the charts and details about how to use this functionality can be found in the supplied "charts" sample.



Most Viewed Articles (in Java )

Latest Articles (in Java)

Comment on this tutorial