Java JFreeChart Tutorial



This is a tutorial on the JFreeChart library in Java.

What is Java JFreeChart?

JFreeChart is a free open source library available for Java that brings in support for high quality, professional looking charts and graphs. Some of the many things you can create using JFreeChart include Pie Charts, Bar charts, Line Charts, Scatter plots and Gantt charts.

It has support for many output types such as PNG and JPG image files as well as Vector images like PDF and SVG. You can also choose to incorporate it together with a GUI library like JavaFX or Swing.

This Java tutorial aims to cover all the different charts (or graphs) and related features available in the JFreeChart library.


Setting JFreeChart in Java

Maven is pretty widely support across the different IDE’s in Java so there shouldn’t be any issues. If it’s your first time using Maven, read up on this setup tutorial to understand how to use it.

Here’s the Maven dependency code for JFreeChart. As of August 2020, version 1.5.0 is the latest (released in 2017).

<dependency>
    <groupId>org.jfree</groupId>
    <artifactId>jfreechart</artifactId>
    <version>1.5.0</version>
</dependency>

If you’re interested in using JFreeChart with JavaFX (and you should be) use the following code instead. If you face any issues, just include both Maven codes as a precaution.

The below version is for JFreeChart with JavaFX support. If you’re going to be using this version, make sure to read up on this tutorial before proceeding any further. It will explain several JavaFX related things you need to know before using it with JavaFX.

<dependency>
    <groupId>org.jfree</groupId>
    <artifactId>jfreechart-fx</artifactId>
    <version>1.0.1</version>
</dependency>

Don’t forget the <dependencies> tag around the <dependency>.


Charts in JFreeChart

JFreeChart has a whole bunch of different graphs and charts available in both 2D and 3D. We can’t possibly hope to cover all of them (as some are pretty niche) so we’re sticking to the most relevant and common charts in JFreeChart.

A list of charts we’re going to cover:


This marks the end of the Java JFreeChart Tutorial. Any suggestions or contributions for CodersLegacy are more than welcome. Questions regarding the article content can be asked in the comments section below.

Leave a Reply

Your email address will not be published. Required fields are marked *