StackedAreaChart Demo : StackedAreaChart « JavaFX « Java






StackedAreaChart Demo

 
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.StackedAreaChart;
import javafx.scene.chart.XYChart;
import javafx.stage.Stage;

public class Main extends Application {
  public static void main(String[] args) {
    launch(args);
  }

  @Override
    public void start(Stage primaryStage) {

        Group root = new Group();
        final NumberAxis xAxis = new NumberAxis(1, 12, 1);
         
        final NumberAxis yAxis = new NumberAxis();
        final StackedAreaChart<Number,Number> stackedAreaChart = new StackedAreaChart<Number,Number>(xAxis,yAxis);
        final XYChart.Series<Number,Number> series1 = new XYChart.Series<Number,Number>();
          
        xAxis.setLabel("Month");
        yAxis.setLabel("Value");
 
        stackedAreaChart.setTitle("StackedAreaChart");
        series1.setName("XYChart.Series 1");
          
        series1.getData().add(new XYChart.Data(1, 100));
        series1.getData().add(new XYChart.Data(2, 200));
        series1.getData().add(new XYChart.Data(10, 150));
 
        XYChart.Series<Number,Number> series2 = new XYChart.Series();
        series2.setName("XYChart.Series 2");
          
        series2.getData().add(new XYChart.Data(1, 50));
        series2.getData().add(new XYChart.Data(2, 200));
        series2.getData().add(new XYChart.Data(10, 260));
         
        stackedAreaChart.getData().addAll(series1, series2);
              
        root.getChildren().addAll(stackedAreaChart);
  
        primaryStage.setScene(new Scene(root, 500, 400));
        primaryStage.show();
    }
}

   
  








Related examples in the same category