Creating and Uploading Chart Themes

Using Jaspersoft Studio, you can create new chart themes that give a custom look to any JFreeChart. You can set the fonts, colors, line widths, and other settings that determine the appearance of charts. Then upload the chart theme for use in reports generated on the server, either on a report-by-report basis or as a global setting for all charts that do not provide their own theme.

To create a new chart theme in Jaspersoft Studio:

1. Select File > New > Other.

The New wizard appears.

2. Expand Jaspersoft Studio, select Chart Themes, and click Next.

The new file dialog box suggests a default file name. Chart themes use the .jrctx file extension.

New Chart Theme in Jaspersoft Studio

3. Specify a location, enter a name, and click Finish.

The chart theme editor appears; it displays several types of charts to help you understand how the theme will be applied to each.

The available options are based on the JFreeChart library used to generate charts.

Jaspersoft Studio supports only the most common options provided by JFreeCharts.

4. In the Outline pane, select each category and review the available options, which appear in the Properties tab (typically found beneath the Preview tab).
5. Select a property to change its value.

Depending on the nature of the property, you might type text, select a color, check or clear a check box, or select a value from a drop-down. As you update the chart theme, the Preview tab shows your changes. For example, select Title in the Outline pane and choose Bottom from the Position drop-down to move the title beneath the chart.

6. Click a chart type in the Preview pane to zoom in to examine the effects of your changes more closely. Click again to zoom out.

A Chart Theme Edited in Jaspersoft Studio

7. To view the XML that defines the chart theme’s appearance, click the Source tab.
8. When you are satisfied with the chart theme, click File > Save to save the chart theme.

This saves the chart theme to your local hard drive.

9. In the Project Explorer, locate and right-click your chart theme, and click Export.
10. In the dialog that appears, expand Java choose JAR file, and click Next.
11. If Java doesn't appear in the dialog, you may need to enable the option: click Preferences>Capabilities and enable the Development > Java option.
12. In the Export dialog, specify a location and a file name for your chart theme JAR.
13. Click Finish.

The chart theme is exported.

14. To use the chart theme in Jaspersoft Studio, you must add the JAR to your project's classpath: in the Project Explorer, right-click the JAR and choose Build Path > Add to Build Path. If you're Project Explorer isn't displayed, click Window > Show View > Other > Project Explorer.

The theme can be used at the report or server level in JasperReports Server. For more information, refer to the JasperReports Server Administrator Guide. In Jaspersoft Studio, you can upload the chart theme to the server using the Repository Explorer; right-click the folder in the repository where the theme should reside, select New > Jarand click Next. You are prompted to enter a name and ID, and to specify the JAR to upload. Once uploaded, you can use the repo: syntax in a report to specify this JAR as your chart theme.