JFreeChart XY Chart - JFreeChart

What is the use of XY Chart in JFree Chart?

XY chart (scatter) is based on one data series consisting a list of X and Y values. Each value pair (X,Y) is a point in a coordinate system. Here, one value will determine the horizontal (X) position, and the other will determine the vertical (Y) position. This chapter will explain you how to use JFreeChart to create XY Chart from a given set of business data.

Business Data

For example if you want to create an XY chart for all major browsers. Here, different performance scores are gathered from different categories of people as shown below

Firefox

Category(X)

Score(Y)

1.0

1.0

2.0

4.0

3.0

3.0

Chrome

Category(X)

Score(Y)

1.0

4.0

2.0

5.0

3.0

6.0

IE

Category(X)

Score(Y)

3.0

4.0

4.0

5.0

5.0

4.0

AWT Based Application

Below is the code to create an XY Chart from the information given above and this code will help you to embed an XY chart in any AWT based application.

Keep the above Java code in XYLineChart_AWT.java file, and then compile and run it from the command prompted as:

If everything is working fine, it will compile and run to generate the following XY Graph

xychart_awt.jpg

JPEG Image Creation

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

Keep the above Java code in XYLineChart_image.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 XYLineChart.jpeg in your current directory.

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

JFreeChart Topics