Example usage for javafx.scene.chart XYChart.Series getData

List of usage examples for javafx.scene.chart XYChart.Series getData

Introduction

In this page you can find the example usage for javafx.scene.chart XYChart.Series getData.

Prototype

public final ObservableList<Series<X, Y>> getData() 

Source Link

Usage

From source file:Main.java

public static void setupXAxis(NumberAxis numberAxis,
        ObservableList<XYChart.Series<Number, Number>> seriesList) {
    long min = Long.MAX_VALUE;
    long max = 0;

    for (XYChart.Series<Number, ?> series : seriesList) {
        for (Data<Number, ?> data : series.getData()) {
            min = Math.min(data.getXValue().longValue(), min);
            max = Math.max(data.getXValue().longValue(), max);
        }//from   ww  w. j av  a  2s .com
    }
    setupXAxis(numberAxis, min, max);
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    Group root = new Group();

    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis();

    xAxis.setLabel("Month");
    yAxis.setLabel("Value");

    final AreaChart<String, Number> areaChart = new AreaChart<String, Number>(xAxis, yAxis);

    areaChart.setTitle("AreaChart");
    XYChart.Series series = new XYChart.Series();
    series.setName("XYChart.Series");

    series.getData().add(new XYChart.Data("January", 100));
    series.getData().add(new XYChart.Data("February", 200));
    series.getData().add(new XYChart.Data("March", 50));

    areaChart.getData().add(series);//from   w  w  w . j a  v a  2  s  .co  m

    root.getChildren().add(areaChart);

    primaryStage.setScene(new Scene(root, 500, 400));
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    sac.setTitle("title");
    XYChart.Series<Number, Number> seriesApril = new XYChart.Series<>();
    seriesApril.setName("April");
    seriesApril.getData().add(new XYChart.Data(1, 4));
    seriesApril.getData().add(new XYChart.Data(3, 10));
    seriesApril.getData().add(new XYChart.Data(6, 15));
    XYChart.Series<Number, Number> seriesMay = new XYChart.Series<>();
    seriesMay.setName("May");
    seriesMay.getData().add(new XYChart.Data(1, 23));
    seriesMay.getData().add(new XYChart.Data(7, 26));
    seriesMay.getData().add(new XYChart.Data(10, 26));
    Scene scene = new Scene(sac, 800, 600);
    sac.getData().addAll(seriesApril, seriesMay);
    stage.setScene(scene);//w w  w. j av a 2  s  . c  o  m
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis();
    xAxis.setLabel("Month");

    final LineChart<String, Number> lineChart = new LineChart<String, Number>(xAxis, yAxis);

    lineChart.setTitle("My Chart");

    XYChart.Series<String, Number> series = new XYChart.Series<String, Number>();
    series.setName("My data");

    series.getData().add(new XYChart.Data<String, Number>("Jan", 23));
    series.getData().add(new XYChart.Data<String, Number>("Feb", 114));
    series.getData().add(new XYChart.Data<String, Number>("Mar", 15));
    series.getData().add(new XYChart.Data<String, Number>("Apr", 24));
    series.getData().add(new XYChart.Data<String, Number>("May", 134));

    Scene scene = new Scene(lineChart, 800, 600);
    lineChart.getData().add(series);/*from www. j  a  va  2  s .  com*/

    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    final NumberAxis xAxis = new NumberAxis();
    final CategoryAxis yAxis = new CategoryAxis();
    final BarChart<Number, String> bc = new BarChart<Number, String>(xAxis, yAxis);
    bc.setTitle("Summary");
    xAxis.setLabel("Value");
    xAxis.setTickLabelRotation(90);/*from  ww w. ja v  a2s .  c o  m*/
    yAxis.setLabel("Item");

    XYChart.Series series1 = new XYChart.Series();
    series1.setName("2003");
    series1.getData().add(new XYChart.Data(2, itemA));
    series1.getData().add(new XYChart.Data(20, itemB));
    series1.getData().add(new XYChart.Data(10, itemC));

    XYChart.Series series2 = new XYChart.Series();
    series2.setName("2004");
    series2.getData().add(new XYChart.Data(50, itemA));
    series2.getData().add(new XYChart.Data(41, itemB));
    series2.getData().add(new XYChart.Data(45, itemC));

    XYChart.Series series3 = new XYChart.Series();
    series3.setName("2005");
    series3.getData().add(new XYChart.Data(45, itemA));
    series3.getData().add(new XYChart.Data(44, itemB));
    series3.getData().add(new XYChart.Data(18, itemC));

    Timeline tl = new Timeline();
    tl.getKeyFrames().add(new KeyFrame(Duration.millis(500), new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent actionEvent) {
            for (XYChart.Series<Number, String> series : bc.getData()) {
                for (XYChart.Data<Number, String> data : series.getData()) {
                    data.setXValue(Math.random() * 100);
                }
            }
        }
    }));
    tl.setCycleCount(Animation.INDEFINITE);
    tl.play();

    Scene scene = new Scene(bc, 800, 600);
    bc.getData().addAll(series1, series2, series3);
    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    Group root = new Group();

    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis();

    xAxis.setLabel("Month");
    xAxis.setCategories(//  www.  j a va 2s  .  c  o  m
            FXCollections.<String>observableArrayList(Arrays.asList("January", "February", "March")));
    yAxis.setLabel("Value");

    final StackedBarChart<String, Number> stackedBarChart = new StackedBarChart<String, Number>(xAxis, yAxis);
    stackedBarChart.setTitle("StackedBarChart");

    XYChart.Series<String, Number> series1 = new XYChart.Series();
    series1.setName("XYChart.Series 1");

    series1.getData().add(new XYChart.Data("January", 100));
    series1.getData().add(new XYChart.Data("February", 200));
    series1.getData().add(new XYChart.Data("March", 50));

    XYChart.Series<String, Number> series2 = new XYChart.Series();
    series2.setName("XYChart.Series 2");

    series2.getData().add(new XYChart.Data("January", 150));
    series2.getData().add(new XYChart.Data("February", 100));
    series2.getData().add(new XYChart.Data("March", 60));

    stackedBarChart.getData().addAll(series1, series2);

    root.getChildren().addAll(stackedBarChart);

    primaryStage.setScene(new Scene(root, 500, 400));
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    stage.setTitle("Area Chart Sample");
    final NumberAxis xAxis = new NumberAxis(1, 30, 1);
    final NumberAxis yAxis = new NumberAxis(-5, 27, 5);
    final AreaChart<Number, Number> ac = new AreaChart<Number, Number>(xAxis, yAxis);
    xAxis.setForceZeroInRange(true);// w w  w  .  j ava 2 s  .  c o m

    ac.setTitle("Temperature Monitoring (in Degrees C)");

    XYChart.Series series1 = new XYChart.Series();
    series1.setName("March");
    series1.getData().add(new XYChart.Data(0, -2));
    series1.getData().add(new XYChart.Data(3, -4));
    series1.getData().add(new XYChart.Data(6, 0));
    series1.getData().add(new XYChart.Data(9, 5));

    XYChart.Series series2 = new XYChart.Series();
    series2.setName("April");
    series2.getData().add(new XYChart.Data(0, 4));
    series2.getData().add(new XYChart.Data(3, 10));
    series2.getData().add(new XYChart.Data(6, 15));
    series2.getData().add(new XYChart.Data(9, 8));

    XYChart.Series series3 = new XYChart.Series();
    series3.setName("May");
    series3.getData().add(new XYChart.Data(0, 20));
    series3.getData().add(new XYChart.Data(3, 15));
    series3.getData().add(new XYChart.Data(6, 13));
    series3.getData().add(new XYChart.Data(9, 12));

    Scene scene = new Scene(ac, 800, 600);
    //scene.getStylesheets().add("areachartsample/Chart.css");
    ac.setHorizontalZeroLineVisible(true);
    ac.getData().addAll(series1, series2, series3);
    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis();
    xAxis.setLabel("Month");
    final LineChart<String, Number> lineChart = new LineChart<String, Number>(xAxis, yAxis);

    lineChart.setTitle("My Chart");

    XYChart.Series<String, Number> series1 = new XYChart.Series<String, Number>();
    series1.setName("Portfolio 1");

    series1.getData().add(new XYChart.Data<String, Number>("Jan", 23));
    series1.getData().add(new XYChart.Data<String, Number>("Feb", 14));
    series1.getData().add(new XYChart.Data<String, Number>("Mar", 15));

    XYChart.Series<String, Number> series2 = new XYChart.Series<String, Number>();
    series2.setName("Portfolio 2");
    series2.getData().add(new XYChart.Data<String, Number>("Jan", 33));
    series2.getData().add(new XYChart.Data<String, Number>("Feb", 34));
    series2.getData().add(new XYChart.Data<String, Number>("Mar", 25));
    series2.getData().add(new XYChart.Data<String, Number>("Apr", 44));

    XYChart.Series<String, Number> series3 = new XYChart.Series<String, Number>();
    series3.setName("Portfolio 3");
    series3.getData().add(new XYChart.Data<String, Number>("Jan", 44));
    series3.getData().add(new XYChart.Data<String, Number>("Feb", 35));
    series3.getData().add(new XYChart.Data<String, Number>("Mar", 36));
    series3.getData().add(new XYChart.Data<String, Number>("Apr", 33));
    series3.getData().add(new XYChart.Data<String, Number>("May", 31));

    Scene scene = new Scene(lineChart, 800, 600);
    lineChart.getData().addAll(series1, series2, series3);

    stage.setScene(scene);/*  w  w  w  .jav  a2s . c o m*/
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    final NumberAxis xAxis = new NumberAxis();
    final NumberAxis yAxis = new NumberAxis();
    xAxis.setLabel("Number of Month");
    final LineChart<Number, Number> lineChart = new LineChart<Number, Number>(xAxis, yAxis);

    lineChart.setTitle("Line Chart");
    XYChart.Series<Number, Number> series = new XYChart.Series<Number, Number>();
    series.setName("My Data");
    // populating the series with data
    series.getData().add(new XYChart.Data<Number, Number>(1, 23));
    series.getData().add(new XYChart.Data<Number, Number>(2, 114));
    series.getData().add(new XYChart.Data<Number, Number>(3, 15));
    series.getData().add(new XYChart.Data<Number, Number>(4, 124));

    Scene scene = new Scene(lineChart, 800, 600);
    lineChart.getData().add(series);/*from   ww  w  . jav a  2s  .  c o m*/

    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    stage.setTitle("Bubble Chart Sample");
    final NumberAxis xAxis = new NumberAxis(1, 53, 4);
    final NumberAxis yAxis = new NumberAxis(0, 80, 10);
    final BubbleChart<Number, Number> blc = new BubbleChart<Number, Number>(xAxis, yAxis);
    xAxis.setLabel("Week");
    xAxis.setTickLabelFill(Color.CHOCOLATE);
    xAxis.setMinorTickCount(4);/*from   w  w w . j  a va  2  s . com*/

    yAxis.setLabel("Product Budget");
    yAxis.setTickLabelFill(Color.CHOCOLATE);
    yAxis.setTickLabelGap(10);
    yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis, "$ ", null));

    blc.setTitle("Budget Monitoring");

    XYChart.Series series1 = new XYChart.Series();
    series1.setName("Product 1");
    series1.getData().add(new XYChart.Data(3, 35, 2));
    series1.getData().add(new XYChart.Data(12, 60, 1.8));
    series1.getData().add(new XYChart.Data(15, 15, 7));
    series1.getData().add(new XYChart.Data(22, 30, 2.5));
    series1.getData().add(new XYChart.Data(28, 20, 1));
    series1.getData().add(new XYChart.Data(35, 41, 5.5));
    series1.getData().add(new XYChart.Data(42, 17, 9));
    series1.getData().add(new XYChart.Data(49, 30, 1.8));

    XYChart.Series series2 = new XYChart.Series();
    series2.setName("Product 2");
    series2.getData().add(new XYChart.Data(8, 15, 2));
    series2.getData().add(new XYChart.Data(13, 23, 1));
    series2.getData().add(new XYChart.Data(15, 45, 3));
    series2.getData().add(new XYChart.Data(24, 30, 4.5));
    series2.getData().add(new XYChart.Data(38, 78, 1));
    series2.getData().add(new XYChart.Data(40, 41, 7.5));
    series2.getData().add(new XYChart.Data(45, 57, 2));
    series2.getData().add(new XYChart.Data(47, 23, 3.8));

    Scene scene = new Scene(blc);
    blc.getData().addAll(series1, series2);
    //scene.getStylesheets().add("bubblechartsample/Chart.css");
    stage.setScene(scene);
    stage.show();
}