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

@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 a va 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));
    series1.getData().add(new XYChart.Data(12, -4));
    series1.getData().add(new XYChart.Data(15, 6));
    series1.getData().add(new XYChart.Data(18, 8));
    series1.getData().add(new XYChart.Data(21, 14));
    series1.getData().add(new XYChart.Data(24, 4));
    series1.getData().add(new XYChart.Data(27, 6));
    series1.getData().add(new XYChart.Data(30, 6));

    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));
    series2.getData().add(new XYChart.Data(12, 5));
    series2.getData().add(new XYChart.Data(15, 18));
    series2.getData().add(new XYChart.Data(18, 15));
    series2.getData().add(new XYChart.Data(21, 13));
    series2.getData().add(new XYChart.Data(24, 19));
    series2.getData().add(new XYChart.Data(27, 21));
    series2.getData().add(new XYChart.Data(30, 21));

    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));
    series3.getData().add(new XYChart.Data(12, 14));
    series3.getData().add(new XYChart.Data(15, 18));
    series3.getData().add(new XYChart.Data(18, 25));
    series3.getData().add(new XYChart.Data(21, 25));
    series3.getData().add(new XYChart.Data(24, 23));
    series3.getData().add(new XYChart.Data(27, 26));
    series3.getData().add(new XYChart.Data(30, 26));

    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:com.deicos.lince.components.SinChartComponent.java

public SinChartComponent() {
    NumberAxis xAxis = new NumberAxis();
    xAxis.setLabel("x");
    NumberAxis yAxis = new NumberAxis();
    yAxis.setLabel("y");
    XYChart.Series<Number, Number> series = new XYChart.Series<>();
    series.setName("Sine");
    ObservableList<XYChart.Data<Number, Number>> data = series.getData();
    for (double x = -Math.PI; x < Math.PI; x += 0.5) {
        data.add(new XYChart.Data<Number, Number>(x, 10 * Math.sin(x)));
    }//  w ww . j av  a 2  s .  c  o m
    LineChart<Number, Number> lineChart = new LineChart<Number, Number>(xAxis, yAxis);
    lineChart.setTitle("Sine function");
    lineChart.getData().add(series);

    getChildren().add(lineChart);
}

From source file:demo.components.SinChartComponent.java

public SinChartComponent() {

    NumberAxis xAxis = new NumberAxis();
    xAxis.setLabel("x");

    NumberAxis yAxis = new NumberAxis();
    yAxis.setLabel("y");

    XYChart.Series<Number, Number> series = new XYChart.Series<>();
    series.setName("Sine");

    ObservableList<XYChart.Data<Number, Number>> data = series.getData();

    for (double x = -Math.PI; x < Math.PI; x += 0.5) {
        data.add(new XYChart.Data<Number, Number>(x, 10 * Math.sin(x)));
    }//from   w  w  w  .j  a  v  a 2s.  c om

    LineChart<Number, Number> lineChart = new LineChart<Number, Number>(xAxis, yAxis);
    lineChart.setTitle("Sine function");
    lineChart.getData().add(series);

    getChildren().add(lineChart);
}

From source file:org.jacp.demo.components.ContactChartViewComponent.java

private void addData(final XYChart.Series<String, Number> series, final List<Data<String, Number>> data) {
    this.bc.getData().add(series);
    series.getData().addAll(data);
}

From source file:Main.java

@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);//  www .jav a  2s.  c  o  m
    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();
}

From source file:gui.accessories.BattleSimFx.java

private BarChart createBarChart() {
    CategoryAxis xAxis = new CategoryAxis();
    xAxis.setCategories(FXCollections.<String>observableArrayList(tableModel.getColumnNames()));
    xAxis.setLabel("Year");

    double tickUnit = tableModel.getTickUnit();

    NumberAxis yAxis = new NumberAxis();
    yAxis.setTickUnit(tickUnit);/*w  w  w  . j a  v a  2  s .c  om*/
    yAxis.setLabel("Units Sold");

    final BarChart aChart = new BarChart(xAxis, yAxis, tableModel.getBarChartData());
    tableModel.addTableModelListener(new TableModelListener() {

        @Override
        public void tableChanged(TableModelEvent e) {
            if (e.getType() == TableModelEvent.UPDATE) {
                final int row = e.getFirstRow();
                final int column = e.getColumn();
                final Object value = ((SampleTableModel) e.getSource()).getValueAt(row, column);

                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        XYChart.Series<String, Number> s = (XYChart.Series<String, Number>) aChart.getData()
                                .get(row);
                        BarChart.Data data = s.getData().get(column);
                        data.setYValue(value);
                    }
                });
            }
        }
    });
    return aChart;
}

From source file:gui.accessories.GraphPopup.java

private BarChart createBarChartDynamic() {
    SampleTableModel tableModel = new SampleTableModel();
    CategoryAxis xAxis = new CategoryAxis();
    xAxis.setCategories(FXCollections.<String>observableArrayList(tableModel.getColumnNames()));
    xAxis.setLabel("Year");

    double tickUnit = tableModel.getTickUnit();

    NumberAxis yAxis = new NumberAxis();
    yAxis.setTickUnit(tickUnit);//from ww w .  j  ava  2  s.  c  o  m
    yAxis.setLabel("Units Sold");

    final BarChart aChart = new BarChart(xAxis, yAxis, tableModel.getBarChartData());
    aChart.setAnimated(true);
    tableModel.addTableModelListener(new TableModelListener() {

        @Override
        public void tableChanged(TableModelEvent e) {
            if (e.getType() == TableModelEvent.UPDATE) {
                final int row = e.getFirstRow();
                final int column = e.getColumn();
                final Object value = ((SampleTableModel) e.getSource()).getValueAt(row, column);

                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        XYChart.Series<String, Number> s = (XYChart.Series<String, Number>) aChart.getData()
                                .get(row);
                        BarChart.Data data = s.getData().get(column);
                        data.setYValue(value);
                    }
                });
            }
        }
    });
    return aChart;
}

From source file:SampleTableModel.java

private BarChart createBarChart() {
    CategoryAxis xAxis = new CategoryAxis();
    xAxis.setCategories(FXCollections.<String>observableArrayList(tableModel.getColumnNames()));
    xAxis.setLabel("Year");

    double tickUnit = tableModel.getTickUnit();

    NumberAxis yAxis = new NumberAxis();
    yAxis.setTickUnit(tickUnit);/*from  w  ww. ja  va  2s .c  o  m*/
    yAxis.setLabel("Units Sold");

    final BarChart chart = new BarChart(xAxis, yAxis, tableModel.getBarChartData());
    tableModel.addTableModelListener(new TableModelListener() {

        public void tableChanged(TableModelEvent e) {
            if (e.getType() == TableModelEvent.UPDATE) {
                final int row = e.getFirstRow();
                final int column = e.getColumn();
                final Object value = ((SampleTableModel) e.getSource()).getValueAt(row, column);

                Platform.runLater(new Runnable() {
                    public void run() {
                        XYChart.Series<String, Number> s = (XYChart.Series<String, Number>) chart.getData()
                                .get(row);
                        BarChart.Data data = s.getData().get(column);
                        data.setYValue(value);
                    }
                });
            }
        }
    });
    return chart;
}

From source file:MasterRoomControllerFx.rooms.charts.RoomChartController.java

/**
 * Initializes the controller class./*from   w  w  w  . j av a 2  s.  c om*/
 */

@Override
public void initialize(URL url, ResourceBundle rb) {
    pause.setOnFinished(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            getTempData();
            getHumData();

            xAxis.setCategories(FXCollections.<String>observableArrayList(
                    Arrays.asList("00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", "07:00",
                            "08:00", "09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00",
                            "17:00", "18:00", "19:00", "20:00", "21:00", "22:00", "23:00", "24:00")));
            yAxis.setLowerBound(-20);
            yAxis.setUpperBound(100);
            yAxis.setTickUnit(0.5);
            areaChart.setTitle("Temperature and Humidity Monitoring");

            XYChart.Series<String, Number> seriesTemp = new XYChart.Series();
            seriesTemp.setName("Temperature (C)");
            if (!temp.isEmpty()) {
                for (int i = 0; i < temp.size(); i++) {
                    seriesTemp.getData().add(new XYChart.Data<String, Number>(time.get(i), temp.get(i)));
                }
                areaChart.getData().add(seriesTemp);
            }

            XYChart.Series seriesHumidity = new XYChart.Series();
            seriesHumidity.setName("Humidity (%)");
            if (!hum.isEmpty()) {
                for (int i = 0; i < hum.size(); i++) {
                    seriesHumidity.getData().add(new XYChart.Data<String, Number>(time.get(i), hum.get(i)));
                }
                areaChart.getData().add(seriesHumidity);
            }
        }
    });
    pause.play();
}

From source file:smarthome.FXMLDocumentController.java

private void initChart() {

    tempChart.getXAxis().setAutoRanging(true);
    tempChart.getYAxis().setAutoRanging(true);

    XYChart.Series series1 = new XYChart.Series<>();
    series1.setName("Living Room");
    //series.getData().add(new XYChart.Data<>("12", 23));
    series1.getData().add(new XYChart.Data("1", 23));
    series1.getData().add(new XYChart.Data("2", 14));
    series1.getData().add(new XYChart.Data("3", 15));
    series1.getData().add(new XYChart.Data("4", 24));
    series1.getData().add(new XYChart.Data("5", 34));
    series1.getData().add(new XYChart.Data("6", 36));
    series1.getData().add(new XYChart.Data("7", 22));
    series1.getData().add(new XYChart.Data("8", 45));
    series1.getData().add(new XYChart.Data("9", 43));
    series1.getData().add(new XYChart.Data("10", 17));
    series1.getData().add(new XYChart.Data("11", 29));
    series1.getData().add(new XYChart.Data("12", 25));

    XYChart.Series series2 = new XYChart.Series<>();
    series2.setName("Study Room");
    series2.getData().add(new XYChart.Data("1", 13));
    series2.getData().add(new XYChart.Data("2", 34));
    series2.getData().add(new XYChart.Data("3", 15));
    series2.getData().add(new XYChart.Data("4", 34));
    series2.getData().add(new XYChart.Data("5", 54));
    series2.getData().add(new XYChart.Data("6", 66));
    series2.getData().add(new XYChart.Data("7", 32));
    series2.getData().add(new XYChart.Data("8", 15));
    series2.getData().add(new XYChart.Data("9", 33));
    series2.getData().add(new XYChart.Data("10", 47));
    series2.getData().add(new XYChart.Data("11", 19));
    series2.getData().add(new XYChart.Data("12", 55));

    tempChart.getData().add(series1);/*from   w  ww  .  ja v a2s  . co m*/
    tempChart.getData().add(series2);

}