How to add a JFreeChart Pie Chart to a Panel in Netbeans

0
38

How to add a JFreeChart Pie Chart to a Panel in Netbeans

This tutorial is all about How to add a JFreeChart Pie Chart to a Panel in Netbeans. In this tutorial you will learn how to create a professional quality charts in your applications. JFreeChart is an opensource or more specifically, free software. This tutorial uses jfreechart-1.0.19.jar version Package library and Netbeans IDE. Please follow all the steps below to complete this tutorial.

How to add a JFreeChart Pie Chart to a Panel in Netbeans steps

 

Download the JFreeChart library in this website www.jfree.org/jfreechart

If the download is done, add it to your project by right clicking the Libraries folder located in your project and then Add JAR/Folder and browse where your downloaded package located and inside lib folder add all the libraries listed.

The next step is to

Create your project by clicking file at the top of your project and then click new project, you can name your project whatever you want. And then drag a button in your form.

After that you need to import these packages

import javax.swing.UIManager;

import org.jfree.chart.ChartFactory;

import org.jfree.chart.ChartFrame;

import org.jfree.chart.JFreeChart;

above your class and

then double click your button and copy paste the code below:

  1. DefaultPieDataset dataset = new DefaultPieDataset();
  2.  
  3. dataset.setValue("Value 1", new Integer(10));
  4.  
  5. dataset.setValue("Value 2", new Integer(20));
  6.  
  7. dataset.setValue("Value 3", new Integer(30));
  8.  
  9. dataset.setValue("Value 4", new Integer(40));
  10.  
  11. JFreeChart chart = ChartFactory.createPieChart("Your title", dataset, true, true, true);
  12.  
  13. ChartFrame yourFrame = new ChartFrame("Your title", chart);
  14.  
  15. yourFrame.setSize(600, 600);
  16.  
  17. yourFrame.setVisible(true);

 

Then you’re done. Run your project and see if it works.

 

 

For questions or any other concerns or thesis/capstone creation with documentation, you can contact me through the following:

E-Mail: ryansalem221996@gmail.com

Facebook: facebook.com/RyyanSalem

Contact No.: +639098911050

Ryan A. Salem

BSIT Graduate, soon to be MIT.

Java Developer / System Developer

Related topic(s) that you make like:

1.) Create Login Form in Java
2.) How to Add Textbox KeyListener in Java

 

 

Facebook Comments
(Visited 42 times, 1 visits today)

LEAVE A REPLY

Please enter your comment!
Please enter your name here