JFreeChart Line Chart - JFreeChart

What is the use of Line Chart in JFreeChart?

Line chart or line graph will display information as a series of data points (markers) connected by straight line segments. Line Chart is used to show how data changes at equal time frequency.

This chapter will explain you how to use JFreeChart for creating Line Chart from a given set of business data.

Business Data

Below example draws a line chart to show a trend of number of schools opened in different years starting from 1970.

Given data is as follows

Year

Number OF Schools

1970

15

1980

30

1990

60

2000

120

2013

240

2014

300

AWT Based Application

Below is the code for creating Line Chart from the information given above and this code will help you to embed a line chart in any AWT based application.

Keep the above Java code in LineChart_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 Line Graph

linechart_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 LineChart.java file, and then compile and run it from the command prompted as

##START#

$javac LineChart.java

$java LineChart

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

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

JFreeChart Topics