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
-
Download the zip file and expand/extract it to a safe location on your computer.
-
It now needs adding to Netbeans. In Netbeans go to Tools -> Libraries
-
Select 'New Library'
-
Change MyLibrary to JFreechart 1.5.3 and select OK
-
Use Add Jar/Folder to select the extracted folder of the zip file you downloaded.
-
If your project is a Maven Project - Right click on Dependencies in your project, -> Add Dependency
-
Complete the box as follows
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. 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
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.