A report with quantities of different products that are sold in different regions and their sales totals is needed. You are required to create a report that can clearly represent the necessary information, which allows the sales manager to easily compare the sales of different products in different regions.
Here is the sketch that is given to you:
In this lesson, we learn to create a crosstab report from the following tasks:
Before taking this task, make sure you have enabled the Insert field name label with field option in the Options dialog as noted at the end of Lesson 3. Otherwise, the name labels will not be inserted together with the fields when you add fields to the crosstab.
Be sure that JinfonetGourmetJava.cat is specified as the current catalog because it is the catalog we use in this track. For information about specifying this catalog, see Task 1, Step 2 of Lesson 1.
You may notice that here we do not check any columns in the Orders table, that is because in this report, columns in this table are not needed but we need this table to create joins between tables in the query.
In this task, we will format the crosstab to make it look more professional.
By setting the Position property of an object to absolute, the object will be located at the position specified by dragging and dropping or by setting its X and Y coordinate property values. Meanwhile, when objects in a flow layout container have their Position property value set to absolute and are overlapped, we can set the display order of the objects by right-clicking the object and then selecting an item from the Move submenu.
Next, we will edit properties of the crosstab report objects in the Report Inspector to improve the appearance of the report.
Select the two Total cells, the Customers_Country field and the four #,### cells in the crosstab, and then specify their Foreground property to Gray.
Note: If the report does not look correct, you can compare it to the final version of the report provided by JReport. To do so, you will need to save and close this catalog and then open the JinfonetGourmetJava.cat catalog file located at <install_root>\Demo\Reports\TutorialReports
.
When previewing the report, we can see that the crosstab is displayed in two pages. However, with JReport's page mode feature, we can decide how to view a report: in pagination mode or continuous mode. In pagination mode, the page shape and size can be specified in the page panel settings. In continuous mode, the whole report is laid out in a single page, and has no specific shape and size. You can refer to Designing a report page in the Page Reports chapter of the JReport Designer User's Guide for more details about other page related features.
For a crosstab component, when it is in continuous page mode, we can further set another two properties to determine how many rows and columns we would like to view.
After formatting the report step by step in the Task 2, we can then save the report style as a CSS file, which can be applied to other crosstab reports directly.
<install_root>\style
.
The CSS Style Definition for CTCrosstab dialog appears.
Now, the style of the crosstab report has been saved as a CSS file. Properties in the file can be applied to corresponding components of other reports directly by selecting the CSS file in the <Import CSS File...> drop-down list on the Format toolbar of JReport Designer.
In this lesson, we created a crosstab report to represent the product sales analysis of different regions, and then formatted it to improve its appearance. Then, we used the page mode feature to preview the report and edited some properties to reduce the records on the row and column blocks. And finally, we saved the style of the crosstab report as a CSS file so that the styles we defined here can easily be applied to another report.