Adding HTML5 Charts Activity

 

 

 

Step

Action

1. 

Note: Activity End Result

 

 

At the end of this activity, the HTML5 bar chart appears at the end of the salary_report.jrxml report preview as displayed above.

 

To achieve this result, you

1. Add a HTML5 bar chart element to the Summary band of the salary_report.jrxml report 

2. Preview the report in xHTML format

2. 

Note: This activity uses the salary_report.jrxml file.

 

 

Make sure to

 

1. Import salary_report.jrxml file from the Creating a New Report activity

2. Open the salary_report.jrxml file

3. 

Note: The business requirement is to add an HTML5 bar chart to the Summary band of the salary_report.jrxml report.

 

The bar chart should depict the average yearly salary for females and males across all job positions, for each department.

4. 

Begin by inspecting the report's SQL query to become familiar with the report's main dataset

 

In the Outline view, right-click the salary_report node.

5. 

Click the Dataset and Query ... menu item.

6. 

Note: The Dataset and Query Dialog window appears.

 

 

The Text tab displays the SQL query:

 

SELECT public.department.department_description,  public.employee.position_title, public.employee.salary, public.employee.gender

FROM public.department INNER JOIN  public.employee

ON public.department.department_id =  public.employee.department_id

7. 

Note: In the query, the INNER JOIN operation joins the employee table and the department table on the department_id field.

 

The result set include the following fields:

- department_description

- position_title

- salary

- gender

 

The SQL query does not perform any arregate calculations involving groups to summarize the data.

 

The HTML5 Charts element performs the necessary aggregate calculations.

8. 

In the Dataset and Query Dialog window, click the OK button.

9. 

Note: Task 1: Inspect a report's SQL query, is complete.

10. 

Next, preview the report to become familiar with the data itself.

 

Click the Preview tab.

11. 

Note: Page 1 of the report appears.

 

 

Task 2: Preview the report, is complete.

12. 

Next, place an HTML5 Charts element in the Summary band of the report.

 

Click the Design tab.

13. 

To accomodate the size of the HTML5 chart, increase the height of the Summary band.

 

In the Outline view, click the Summary node.

14. 

Click the Properties tab.

15. 

Change the Height to 800 px.

 

Enter 800 px into the Band Properties Height field.

16. 

In the Components Pro section of the Palette, select the HTML5 Charts element.

17. 

Drag the mouse to outline a rectangular area in the Summary band for the HTML5 Charts element to occupy.

18. 

Note: The HTML5 Chart type selection window appears.

 

The Bar chart type is selected by default.

19. 

Click the OK button.

20. 

Note: The HTML5 Charts element appears in the Summary band.

 

 

A static chart image denotes the chart element. The image does not represent actual report data. Real data is rendered when the report runs.

21. 

Next, adjust the size and location of  the HTML5 Charts element.

 

In the Outline view, expand the Summary node.

22. 

Note: In the Outline view, the HTML5 Charts: Bar item appears.

23. 

In the Outline view,

select the HTML5 Charts: Bar item.

24. 

In the Report Editor view, right-click the HTML5 Charts: Bar element.

 

25. 

Click the

Size to Container menu, then the Fit to both 

menu item.

26. 

Note: The HTML5 Charts:Bar element is sized to occupy as much of the Summary band as possible.

27. 

Next, configure the chart to connect it to data fields in the main data set.

 

In the Outline view, right-click the HTML5 Charts: Bar item.

28. 

Click the Edit Chart properties menu item.

29. 

Note: The HTML5 Charts properties window appears.

30. 

Set the title for the bar chart.

 

In the left pane, click the Title field.

31. 

Enter Department Salary Report into the Title field.

32. 

Now, configure the chart data.

 

Click the Chart Data tab.

33. 

Note: The Chart Data tab is active.

 

 

The Dataset Run section of the Dataset sub-tab identifies the dataset for the chart, which can be either the main dataset of the report or a subdataset.

 

This activity uses the main dataset of the report.

34. 

Note: The Filter Expression is used to limit the chart to a subset of the dataset.

 

This activity does not filter the dataset.

35. 

Next, configure the categories, series, and measures of the chart.

 

Click the Configuration sub-tab.

36. 

In the Categories Levels pane, click the Level1 list item.

37. 

Click the Modify button.

38. 

Note: The Categories level window appears.

 

 

The Bucket information tab is active.

39. 

Enter Department into the Name field.

40. 

Next, provide an expression for the Department category to extract the department name from the data.

 

Click the Expression Editor button to the right of the Expression field.

41. 

Note: The Expression Editor window appears.

 

 

The default expression is the "Change Me" text string.

42. 

Double-click the 

department_description

field in the middle pane.

43. 

Note: The $F{department_description} expression appears in the input pane.

44. 

In the Expression Editor window, click the Finish button.

45. 

Note: In the Categories Level window, the $F{department_description} expression appears in the Expression field.

 

The class for this expression is String.

46. 

The Value Class Name is correctly set.

The Order is appropriately set.

 

Click the OK button.

47. 

Next, configure the measure.

 

In the Measures pane, click the Measure1 list item.

48. 

Click the Modify button.

49. 

Note: The Measure window appears.

 

 

The Value definition tab is active.

50. 

Enter Salary into the Name field.

51. 

Enter Average Salary into the Label Expression field.

52. 

Set the Calculation field.

 

Click the Calculation pulldown.

53. 

Click the Average list item.

54. 

Set the Value Expression field.

 

Click the Expression Editor button.

55. 

Note: The Expression Editor window appears.

56. 

Double-click the salary field in the middle pane.

57. 

Note: The $F{salary} expression appears in the input pane.

 

The class for this expression in BigDecimal.

58. 

Click the Finish button.

59. 

Next, change the Value Class name to match the type that the expression returns.

 

In the Measure window, to the right of the Value Class Name field, click the ... button.

60. 

Note: The Open Type window appears.

61. 

As needed, enter BigDecimal - java.math into the input pane.

Double-click the BigDecimal - java.math list item.

62. 

In the Measures window, click the OK button.

63. 

Next, define the series for the chart.

 

In the Series pane, click the Add button.

64. 

Note: The Series Level window appears.

65. 

Enter Gender into the Name field.

66. 

To the right of the Expression field, click the Expression Editor button.

67. 

Note: The Expression Editor window appears.

68. 

Double-click the gender field.

69. 

Note: The $F{gender} expression appears in the input pane.

70. 

Click the Finish button.

71. 

The Value Class Name is correct.

The Order field is appropriately set.

 

In the Series Level window, click the OK button.

72. 

The chart data is configured.

 

Click the OK button.

73. 

Note: Task 3: Place an HTML5 bar chart in the Summary band and configure it, is complete.

74. 

Next, preview the report.

 

Click the Preview tab.

75. 

Note: Page 1 of the report appears.

 

 

The chart is at the end of the report.

76. 

View the chart.

 

Click the Last Page button.

77. 

Page 50 of the report appears, displaying the bar chart.

 

The departments with only female employees or only male employees show just one bar.

78. 

Minimize the Palette to make more horizontal space available to view the chart.

 

Click the Minimize button.

79. 

Click the scrollbar to view the chart legend at the bottom of the page

80. 

Note: The chart legend appears.

 

 

However, the chart is not interactive due to the choice of preview format.

81. 

Note: The bottom two departments do not show bars.

 

 

The salary for the following two departments is an hourly rate instead of an annual rate:

 

- Store Temporary Stockers

- Store Temporary Checkers

 

A Filter Expression could be provided to exclude these two departments.

82. 

Note: The chart is not interactive.

 

 

The chart does not respond to mouse movement or mouse clicks. The preview format is Java.

 

For chart interactivity, the preview format must be xHTML.

83. 

Change the preview format to xHTML.

 

Click the preview format pulldown.

84. 

Click the xHTML menu item.

85. 

Note: The report appears in xHTML format.

 

 

Notice that the report does not have individual pages, and that the scrollbar is not visible.

86. 

Minimize the Project Explorer to increase the horizontal space available to view the report.

 

In the Project Explorer panel, click the Minimize button.

87. 

Now, minimize the Outline view.

 

In the Outline panel, click the Minimize button.

88. 

Note: The scrollbar appears in the Report Editor view.

89. 

Scroll to the bottom of the report to view the chart.

 

Click the scrollbar.

90. 

Note: The bottom of the report appears. The chart legend is visible.

91. 

Point to a chart bar.

92. 

Note: The tooltip bubble appears, displaying the department name and the average salary.

93. 

Point to a chart bar

94. 

Note: Another tooltip appears.

 

95. 

Toggle off the average salary bars for females.

 

In the chart legend, click the Average Salary F graphic.

96. 

Note: The blue bars denoting the female average salary per department disappear.

97. 

Now, toggle on the female average salary per department.

 

In the legend, click the Average Salary F graphic.

98. 

Next, save the report.

 

Click the File menu.

99. 

Click the Save menu item.

100. 

Congratulations!

 

In this activity, you've completed the following four tasks:

 

1. Inspected a report's SQL query

2. Previewed the report

3. Placed an HTML5 bar chart in the summary band and configured it

4. Previewed the report in the xHTML format

End of Procedure.