Creating Category Chart Using JFreeChart

In this basic tutorial, I am walking through how to create category chart using JFreeChart. The program uses the following two jar files, and they come with the JFreeChart itself. You can download JFreeChart at their official website

  • jcommon-1.0.15.jar
  • jfreechart-1.0.12.jar

The program also demonstrates how easily you can save a generated chart to your computer using the Charts Utilities from JFreeChart

package com.kushal.utilities;

import java.util.Date;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;

public class CategoryChartDemo {

	public void createCategoryChart()

		DefaultCategoryDataset  categoryDataset = new DefaultCategoryDataset();

		//Enrollment in Bachelors level
		categoryDataset.setValue(2003, "Bachelors", "2005");
		categoryDataset.setValue(1350, "Bachelors", "2006");
		categoryDataset.setValue(2408, "Bachelors", "2007");
		categoryDataset.setValue(2607, "Bachelors","2008");

		//Enrollment in Masters level
		categoryDataset.setValue(985, "Masters", "2005");
		categoryDataset.setValue(1400, "Masters", "2006");
		categoryDataset.setValue(1634, "Masters", "2007");
		categoryDataset.setValue(978, "Masters", "2008");

		//Enrollment in PhD level
		categoryDataset.setValue(356, "PhD", "2005");
		categoryDataset.setValue(390, "PhD", "2006");
		categoryDataset.setValue(350, "PhD", "2007");
		categoryDataset.setValue(687, "PhD", "2008");

		JFreeChart chart = ChartFactory.createBarChart3D
				     ("Program Enrollment (c)", // Title
				      "Year",              // X-Axis label
				      "Number of Students",// Y-Axis label
				      categoryDataset,         // Dataset
				      true,                     // Show legend


	public void saveChart(JFreeChart chart)
		String fileName="C:/Users/kushal/Desktop/myCategoryChart.jpg";
		try {
			 * This utility saves the JFreeChart as a JPEG
			 * First Parameter: FileName
			 * Second Parameter: Chart To Save
			 * Third Parameter: Height Of Picture
			 * Fourth Parameter: Width Of Picture
	    ChartUtilities.saveChartAsJPEG(new File(fileName), chart, 800, 600);
	} catch (IOException e) {
	    System.err.println("Problem occurred creating chart.");
	public static void main(String args [])
		new CategoryChartDemo().createCategoryChart();



The following is the output when you run this program:

SQL – How To Retrieve Data With Maximum Length?

Suppose you have a schema called mySchema and a table called myTable. You would like to retrieve all data with maximum length (for instance, whose first name is the longest).

The following is a simple query to handle situations like this.

select  * from 
where length(myTable.firstName)=  
(select max(length(myTable.firstName))  
from mySchema.myTable

Simple Huh ! Well it sometimes saves you a minute. The functions are tested to work in DB2/AS-400

100 Plus Agile Terms – A Comprehensive List

(Image Source: Wikipedia / Creative Commons / Author: VersionOne, Inc)

Agile has been a hot topic in the industry. Many companies are converting their work teams into agile – some others, especially the big enterprises with decades of experience in waterfall model are choosing to be hybrid, experimenting stuffs. Google is a hundred percent agile company. In this article I have collected over hundred agile terms worth knowing if you are planning to shift to the Agile paradigm. This is just a list, you can Google the terms to find their meanings (although I plan to have another article sometimes later explaining these terms.)

I have worked on the Waterfall Model for over five years now as a software engineer in Java/J2EE platform, and I have been recently assigned to work on an agile team. This is the first time I will have a real experience of working in an agile environment. I have taken few agile workshops and agile training in the past, I hope those will be helpful.

So here goes the comprehensive list of agile terms. I plan to add more as I discover these terminologies. Keep coming back.
Continue reading