JFreeChart Bar Chart - JFreeChart

How bar Chart is used in JFreeCharts?

This chapter will give you detailed description on how to use JFreeChart for creating Bar Chart from a given set of business data.

A bar chart uses different orientation (horizontal or vertical) bars for showing comparisons in various categories. One axis (domain axis) of the chart shows the specific domain being compared, and the other axis (range axis) represents discrete values.

Business Data

Below example depicts different car statistics with the help of a bar chart. Below is a list of car brands along with their different characteristics, which we will show using a bar chart

Car

Speed

User Rating

Millage

Safety

Fiat

1.0

3.0

5.0

5.0

Audi

5.0

6.0

10.0

4.0

Ford

4.0

2.0

3.0

6.0

AWT Based Application

Below is the code to create a Bar Chart from the above given information and the code helps you to embed a bar chart in any AWT based application.

Let us keep the above Java code in BarChart_AWT.java file, and then compile and run it from the command prompted as −

If everything works well, it will compile and run to generate below Bar Graph

barchart_awt.jpg

JPEG Image Creation

Re-write the above example to generate a JPEG image from a command line.

keep the above Java code in BarChart.java file, and then compile and run it from the command prompted as

If everything is working fine, it will compile and run to create a JPEG image file named BarChart.jpeg in your current directory.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

JFreeChart Topics