JavaFX 8 Tutorial 56 - Pie Chart





The Code written in this tutorial is:


package tutorial.pkg56.pie.chart;



import javafx.application.Application;

import javafx.collections.FXCollections;

import javafx.collections.ObservableList;

import javafx.geometry.Insets;

import javafx.scene.Scene;

import javafx.scene.chart.PieChart;

import javafx.scene.control.Label;

import javafx.scene.input.MouseEvent;

import javafx.scene.layout.BorderPane;

import javafx.scene.text.Font;

import javafx.scene.text.FontWeight;

import javafx.stage.Stage;



/**

 *

 * @author Ram

 */

public class Tutorial56PieChart extends Application {

    private final ObservableList<PieChart.Data> details = FXCollections.observableArrayList();

    private BorderPane root;

    private PieChart pieChart;

 

    @Override

    public void start(Stage primaryStage) {

     

        primaryStage.setTitle("JavaFX 8 Tutorial 58 - Pie Chart and Mouse Event Handler");

        details.addAll(new PieChart.Data("Printing Cost", 20),

                new PieChart.Data("Paper Cost", 25),

                new PieChart.Data("Binding Cost", 30),

                new PieChart.Data("Promotion Cost", 10),

                new PieChart.Data("Transportation Cost", 10),

                new PieChart.Data("Royalty Cost", 15)

            );

     

        root = new BorderPane();

        Scene scene = new Scene(root, 600, 500);

     

        pieChart = new PieChart();

        pieChart.setData(details);

        pieChart.setTitle("Various Expenditures (in %) Incurred In Publishing A Book");

        //pieChart.setLegendSide(Side.BOTTOM);

        //pieChart.setLabelsVisible(true);

        //pieChart.setClockwise(false);

        //pieChart.setStartAngle(90);

        root.setCenter(pieChart);

   

        primaryStage.setScene(scene);

        primaryStage.show();

    }



    /**

     * @param args the command line arguments

     */

    public static void main(String[] args) {

        launch(args);

    }

 

}


Comments

Popular posts from this blog

JavaFX 8 Tutorial 62 - Jasper Report

JavaFX 8 Tutorial 64 Spring Boot CRUD with FXML