Jump to content
We've recently updated our Privacy Statement, available here ×
  • Overview of Customizing Options for JFreeCharts in JasperReports


    JasperReports allows many different visualizations for data in reports. In addition to tables and crosstabs, data can be visualized as charts or widgets. Charts and widgets in JasperReports are implemented using different chart libraries, such as JFreeCharts, HighCharts or FusionCharts. The design of a report created with JasperReports can be accurately adjusted to a defined corporate identity. This also includes the customization of charts embedded into the report.

    This article gives an overview of customizing possibilities for JFreeCharts in JasperReports (and iReport Designer). All possiblities discussed in this article are related to JFreeCharts, so they can be applied both in the community edition as well in the professional or enterprise editions of JasperReports and the iReport Designer.

    Chart Properties

    The most direct way for customizing charts is by accessing the chart’s properties. After you’ve selected the chart in the Report Designer or in the Report Inspector panel, its properties will appear in the Properties panel. The properties for a chart are organized into three groups:

    • Common properties are properties that all JasperReports elements have – like transparency, style or a print when expression
    • Common chart properties can be set for any kind of JFreeChart – e.g. colors for the series, visibility of the legend or displaying and setting the title / subtitle
    • Chart specific properties, which include settings that can be applied only for specific chart types – e.g. configuration of the x- and y-axis or the visibility of shapes on plotted lines

    The screenshot below displays the properties for a 3D Pie JFreeChart. The property groups are marked by grey backgrounds.

    http://blog.itransparent.de/wp-content/uploads/2013/10/pie3d_properties-251x300.png

    Chart Themes

    Using the Properties panel several chart settings can be edited in a quick and easy way. Unfortunately, the property values have to be set manually for each chart and in each report. For example if would be preferable to set the series colors only once and then apply the colors for several charts. To achieve this, JasperReports allows the definition of Chart Themes. The Chart Theme can be designed once and then applied on multiple charts in any report. Another benefit of using Chart Themes is that they enable setting a few more properties which or not available in the Charts Properties panel.

    The iReport Designer includes a Chart Theme designer which simplifies the design of Chart Themes. The properties for a chart can be accessed via the Template Inspector and then edited in the Properties panel. All changes are automatically applied in the Design panel to an example chart. The example chart type can be changed by using the drop-down menu at the top of the panel. The screenshot below shows the Chart Theme designer interface of the iReport Designer.

    http://blog.itransparent.de/wp-content/uploads/2013/10/chart_theme_designer-300x170.png

    To enable a newly designed Chart Theme in iReport so you can apply the theme to charts in reports, the Chart Theme needs to be exported as a JAR file and added to the classpath of iReport. The simplest way to do this is to right-click on the root node in the Template Inspector and select Export to JAR file from the context menu. This way the generated JAR file will be added automatically to the classpath of iReport. After exporting the JAR file from the Chart Theme designer in iReport, the Chart Theme can be accessed in the Properties panel of a chart (using the drop-down list for the property ‘Theme’).

    Chart Customizer Class

    The JFreeCharts library is very powerful and allows the configuration or customization of almost any detail of a chart. The Properties panel for a chart and the Chart Themes display only the most common JFreeChart settings. JasperReports enables the the customization of special chart details by using chart customizer classes. Customizer classes can leverage the full functionality of the JFreeCharts library. For example by using chart customizer classes you can change the line style for a series to dashed; change the style for bars to custom gradients or even striped patterns; show a zero-line, marker-lines or marker-regions; read all design information from a database, etc.

    Similarly to scriptlets, chart customizer classes have to be implemented separately from the report in Java using an IDE, such as Eclipse or Netbeans. After implementing the chart customizer class, the implementation needs to be compiled and exported to a JAR file. Then this JAR file has to be added to the classpath of the iReport Designer, so the customizer class can be found when the report is executed. The customizer class is then assigned directly to a (JFreeChart) chart in the report by adding the package name and the class name of the customizer class in the ‘Customizer Class’ property for the selected chart in its Properties panel. I will give a more detailed introduction on implementing and using chart customizer classes in the next blog post.

    Conclusion

    This article gave an overview of customizing possibilities for JFreeCharts in JasperReports (and iReport Designer). Charts can be customized via the Properties panel for the selected chart, Chart Themes or Chart Customizer Classes. The next blog post will focus on the details for the implementation and usage of chart customizer classes.


    User Feedback

    Recommended Comments

    There are no comments to display.



    Guest
    This is now closed for further comments

×
×
  • Create New...