Simple Chart Application using JavaFx 2.0


Following Example show how to create a  pie chart using JavaFx2.0.While you go through the program your can get a idea way that it works.
Source Code
// Comment
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package chartsamples;

/**
 *
 * @author sabari
 */
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.chart.*;
import javafx.scene.Group;
 
public class simplepiechart extends Application {
 
    @Override public void start(Stage stage) {
        Scene scene = new Scene(new Group());
        stage.setTitle("Large Cities");
        stage.setWidth(500);
        stage.setHeight(500);
 
        ObservableList pieChartData =
                FXCollections.observableArrayList(
                new PieChart.Data("Chennai", 40),
                new PieChart.Data("Madurai", 20),
                new PieChart.Data("Delhi", 50),
                new PieChart.Data("Goa", 20),
                new PieChart.Data("Hyderabad", 30),
                new PieChart.Data("Bangalore", 35),
                new PieChart.Data("Mumbai", 60));
        final PieChart chart = new PieChart(pieChartData);
        chart.setTitle("Large Cities");

        ((Group) scene.getRoot()).getChildren().add(chart);
        stage.setScene(scene);
        stage.show();
    }
 
    public static void main(String[] args) {
        launch(args);
    }
}



Output Screen
raja P Web Developer

3 comments:

Related Posts Plugin for WordPress, Blogger...