Example usage for javafx.scene.chart CategoryAxis CategoryAxis

List of usage examples for javafx.scene.chart CategoryAxis CategoryAxis

Introduction

In this page you can find the example usage for javafx.scene.chart CategoryAxis CategoryAxis.

Prototype

public CategoryAxis() 

Source Link

Document

Create a auto-ranging category axis with an empty list of categories.

Usage

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    CategoryAxis xAxis = new CategoryAxis();
    NumberAxis yAxis = new NumberAxis();
    BarChart barChart = new BarChart(xAxis, yAxis, getChartData());
    barChart.setBarGap(0.2);//from w  w w . j a  va2s. co  m
    barChart.setTitle("A");
    primaryStage.setTitle("BarChart example");

    StackPane root = new StackPane();
    root.getChildren().add(barChart);
    primaryStage.setScene(new Scene(root, 400, 250));
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    CategoryAxis xAxis = new CategoryAxis();
    NumberAxis yAxis = new NumberAxis();
    LineChart lineChart = new LineChart(xAxis, yAxis);
    lineChart.setData(getChartData());//from  w  w w .ja  va2s .  co m
    lineChart.setTitle("Chart");
    primaryStage.setTitle("LineChart example");

    StackPane root = new StackPane();
    root.getChildren().add(lineChart);
    primaryStage.setScene(new Scene(root, 400, 250));
    primaryStage.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(/*from  w w  w. j a  v a2  s  .co  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 primaryStage) {
    CategoryAxis xAxis = new CategoryAxis();
    NumberAxis yAxis = new NumberAxis();
    BarChart barChart = new BarChart(xAxis, yAxis, getChartData());
    barChart.setCategoryGap(0.2);//w w  w .  j a  v  a  2 s  . c  o m
    System.out.println(barChart.getBarGap());
    System.out.println(barChart.getCategoryGap());
    barChart.setTitle("A");
    primaryStage.setTitle("BarChart example");

    StackPane root = new StackPane();
    root.getChildren().add(barChart);
    primaryStage.setScene(new Scene(root, 400, 250));
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(final Stage stage) {
    stage.setTitle("");
    stage.setWidth(500);//from   ww  w .  ja va  2s .c  o m
    stage.setHeight(500);
    Scene scene = new Scene(new Group());

    VBox root = new VBox();
    NumberAxis lineYAxis = new NumberAxis(0, 100, 10);
    CategoryAxis lineXAxis = new CategoryAxis();

    BarChart barChart = new BarChart(lineXAxis, lineYAxis);

    lineYAxis.setLabel("Sales");
    lineXAxis.setLabel("Products");

    root.getChildren().addAll(barChart);
    scene.setRoot(root);

    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);// w ww  .  j  a va2s .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: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);/*  w  ww.j  a v  a2 s .  com*/
    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: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 ww.  j  a  v a 2  s  .com*/
    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:org.jacp.demo.components.ContactChartViewComponent.java

protected BarChart<String, Number> createChart() {

    this.xAxis = new CategoryAxis();
    this.yAxis = new NumberAxis();
    this.yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(this.yAxis, "$", null));
    this.bc = new BarChart<String, Number>(this.xAxis, this.yAxis);
    this.bc.setAnimated(true);
    this.bc.setTitle(" ");

    this.xAxis.getStyleClass().add("jacp-bar");
    this.yAxis.getStyleClass().add("jacp-bar");
    this.xAxis.setLabel("Year");
    this.yAxis.setLabel("Price");

    this.series1 = new XYChart.Series<String, Number>();
    this.series1.setName("electronic");
    this.series2 = new XYChart.Series<String, Number>();
    this.series2.setName("clothes");
    this.series3 = new XYChart.Series<String, Number>();
    this.series3.setName("hardware");
    this.series4 = new XYChart.Series<String, Number>();
    this.series4.setName("books");

    GridPane.setHalignment(this.bc, HPos.CENTER);
    GridPane.setVgrow(this.bc, Priority.ALWAYS);
    GridPane.setHgrow(this.bc, Priority.ALWAYS);
    GridPane.setMargin(this.bc, new Insets(0, 6, 0, 0));
    return this.bc;
}

From source file:gui.accessories.GraphPopup.java

private BarChart createBarChart() {
    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis();

    List<Nacao> nations = new ArrayList<Nacao>(WorldFacadeCounselor.getInstance().getNacoes().values());
    ComparatorFactory.getComparatorNationVictoryPointsSorter(nations);
    xAxis.setCategories(FXCollections.<String>observableList(getNames(nations)));

    //format axis
    yAxis.setTickUnit(200);/* w  ww  . ja  va2s. c om*/
    yAxis.setLabel(labels.getString("PONTOS.VITORIA"));
    //xAxis.setLabel(labels.getString("NACAO"));
    xAxis.setTickMarkVisible(false);

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

    for (Nacao nation : WorldFacadeCounselor.getInstance().getNacoes().values()) {
        final XYChart.Data data = new XYChart.Data(nation.getPontosVitoria(), nation.getNome());
        series.getData().add(data);
    }

    //
    final BarChart<Number, String> stackedBarChart = new BarChart<Number, String>(yAxis, xAxis);
    //        stackedBarChart.setTitle(labels.getString("PONTOS.VITORIA"));
    stackedBarChart.getData().addAll(series);
    stackedBarChart.setLegendVisible(false);
    //        stackedBarChart.setCategoryGap(0.2);

    return stackedBarChart;
}