JavaFX Pie Chart


JavaFX Pie Chart Tutorial:

  • The PieChart Class draws data in the form of circle which is divided in slices.
  • Every slice represents a percentage (part) for a particular value.
  • labelsVisible property is used to display labels on it.
  • Clockwise property is used for placing the slice in clock-wise manner.

Creating a Pie Chart :

PieChart pieChart =new PieChart(valueList);
Here valueList is list of data which is represented by the PieChart.

Constructors :

  • PieChart()Construct a new empty PieChart.
  • PieChart(ObservableList data)Construct a new PieChart with the given data.

Example of pie chart:

package javafxtuts;

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.chart.PieChart;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

 * @author
public class Javafxtuts extends Application {
    public void start(Stage primaryStage) {
         Pane root = new Pane();
//        PieChart.Data JavaFX =new PieChart.Data("JavaFX",50);
//        we use it directly in the observableList
//        Here observableArrayList is method of the FXColloctions.         
        ObservableList valueList =FXCollections.observableArrayList(
                new PieChart.Data("JavaAWT",13),
                new PieChart.Data("JavaSwing",38),
                new PieChart.Data("JavaFX",48));
        // create a pieChart with valueList data.
        PieChart pieChart =new PieChart(valueList);
        pieChart.setTitle("Popularity of Java GUI");
        //adding pieChart to the root.
        Scene scene = new Scene(root, 450, 450);

     * @param args the command line arguments
    public static void main(String[] args) {

Output :


Leave A Reply