Create Charts using JFreeChart - tstorrnetnz/teaching2022 GitHub Wiki

It is easy to create line graphs and pie charts using JFreeChart JFreeChart. This tutorial will get you started.

Installation

  1. Download the zip file and expand/extract it to a safe location on your computer.

  2. It now needs adding to Netbeans. In Netbeans go to Tools -> Libraries dependencies

  3. Select new library'New Library'

  4. Change MyLibrary to JFreechart 1.5.3 and select OK

  5. Use Add Jar/Folder to select the extracted folder of the zip file you downloaded.

  6. If your project is a Maven Project - Right click on Dependencies in your project, -> Add Dependencydependency

  7. Complete the box as follows info

Using JFreechart

JFreechart is well documented with quite a few examples available for you to look at on the internet. I have made one example and produced this nice pie chart. pie chart The code for this can be found here.. It uses two classes - a separate main class to run the GUI. It has a separate method to create a dataset and another method to create a chart. The constructor creates a dataset, a chart and a chartpanel. It then puts the chart in the chartpanel of a pane. The main method in the separate Main class controls/starts this process.

Examples

There are plenty of different charts that you can make have a look here, for example jfreechart

It should be straightforward to read data from a text file into an arraylist and then use the data in the arraylist for a chart. Youtube has planty of tutorials on using Jfreechart. The API documentation is also available. I suggest making a separate netbeans program to see how Jfreechart works with your sample data before using it in your real project.