Adding Charts to Web-Based J2EE Applications, Page 3
More Advanced Charts
You have thus far seen examples of pie charts. More complex types of charts can show one or more series within one or more categories. JFreeChart's CategoryDataset interface represents data containing series grouped within categories.
I have created a second Java class in the file EmployeesByDeptAndQtr.java. Like the previous class, EmployeesByDeptAndQtr also implements Cewolf's DatasetProducer interface. As its name implies, this class executes a database query that will display head counts for each department, categorized by the quarter of the employee's hire date. Here's the query sent to the database:
SELECT COUNT(emp_id), QUARTER(emp.hire_date) quarter, dept.name FROM emp, dept WHERE emp.dept_id = dept.dept_id GROUP BY dept.name,QUARTER(emp.hire_date);
The content of categorychart.jsp should look familiar as it uses many of the same constructs as piechart.jsp. It declares a DatasetProducer instance, and then lists a set of JSP tags to manage the charts. This JSP file contains separate tags for chart types 'horizontalBar3D', 'verticalBar3D', and 'line'. All three charts represent the same CategoryDataset (provided by the DatasetProducer). Only two new tag attributes are introduced: xaxislabel and yaxislabel. Figure 2 shows the resulting Web page. Below are the three chart images produced in greater detail:
Figure 2. Various Category Charts
This article's intended purpose was to provide you with an introduction to creating graphic charts using JFreeChart and Cewolf. I strongly encourage you to visit each site and explore the additional chart types and chart enhancements that are available to you. Extensive documentation of JFreeChart is available for purchase. Both projects have community forums to help answer questions. Also, both sites offer on-line Javadocs that document source code. By combining JFreeChart and Cewolf, J2EE developers have a useful, and easy to use, tool that can be used to satisfy user's data analysis requirements.
About the Author
Michael Klaene is a Senior Consultant with Sogeti LLC. He has spent over 7 years in IT, specializing in J2EE and Oracle analysis and development.
Page 3 of 3