javafx.scene.chart.BarChart Java Examples

The following examples show how to use javafx.scene.chart.BarChart. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SwingInterop.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
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);
    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;
}
 
Example #2
Source File: BarChartSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public BarChartSample() {
    String[] years = {"2007", "2008", "2009"};
    CategoryAxis xAxis = new CategoryAxis();
    xAxis.setCategories(FXCollections.<String>observableArrayList(years));
    NumberAxis yAxis = new NumberAxis("Units Sold", 0.0d, 3000.0d, 1000.0d);
    ObservableList<BarChart.Series> barChartData = FXCollections.observableArrayList(
        new BarChart.Series("Apples", FXCollections.observableArrayList(
           new BarChart.Data(years[0], 567d),
           new BarChart.Data(years[1], 1292d),
           new BarChart.Data(years[2], 1292d)
        )),
        new BarChart.Series("Lemons", FXCollections.observableArrayList(
           new BarChart.Data(years[0], 956),
           new BarChart.Data(years[1], 1665),
           new BarChart.Data(years[2], 2559)
        )),
        new BarChart.Series("Oranges", FXCollections.observableArrayList(
           new BarChart.Data(years[0], 1154),
           new BarChart.Data(years[1], 1927),
           new BarChart.Data(years[2], 2774)
        ))
    );
    BarChart chart = new BarChart(xAxis, yAxis, barChartData, 25.0d);
    getChildren().add(chart);
}
 
Example #3
Source File: ImageBarChartSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public ImageBarChartSample() {

        String imageBarChartCss = ImageBarChartSample.class.getResource("ImageBarChart.css").toExternalForm();

        BarChart barChart = new BarChart(new CategoryAxis(), new NumberAxis());
        barChart.setLegendVisible(false);
        barChart.getStylesheets().add(imageBarChartCss);

        barChart.getData().add(
                new XYChart.Series<String, Integer>("Sales Per Product",
                FXCollections.observableArrayList(
                new XYChart.Data<String, Integer>("SUV", 120),
                new XYChart.Data<String, Integer>("Sedan", 50),
                new XYChart.Data<String, Integer>("Truck", 180),
                new XYChart.Data<String, Integer>("Van", 20))));

        Scene scene = new Scene(barChart, 350, 300);
        scene.getStylesheets().add(ImageBarChartSample.class.getResource("ImageBarChart.css").toString());
        getChildren().add(barChart);
    }
 
Example #4
Source File: ImageBarChartSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public ImageBarChartSample() {

        String imageBarChartCss = ImageBarChartSample.class.getResource("ImageBarChart.css").toExternalForm();

        BarChart barChart = new BarChart(new CategoryAxis(), new NumberAxis());
        barChart.setLegendVisible(false);
        barChart.getStylesheets().add(imageBarChartCss);

        barChart.getData().add(
                new XYChart.Series<String, Integer>("Sales Per Product",
                FXCollections.observableArrayList(
                new XYChart.Data<String, Integer>("SUV", 120),
                new XYChart.Data<String, Integer>("Sedan", 50),
                new XYChart.Data<String, Integer>("Truck", 180),
                new XYChart.Data<String, Integer>("Van", 20))));

        Scene scene = new Scene(barChart, 350, 300);
        scene.getStylesheets().add(ImageBarChartSample.class.getResource("ImageBarChart.css").toString());
        getChildren().add(barChart);
    }
 
Example #5
Source File: BarChartSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public BarChartSample() {
    String[] years = {"2007", "2008", "2009"};
    CategoryAxis xAxis = new CategoryAxis();
    xAxis.setCategories(FXCollections.<String>observableArrayList(years));
    NumberAxis yAxis = new NumberAxis("Units Sold", 0.0d, 3000.0d, 1000.0d);
    ObservableList<BarChart.Series> barChartData = FXCollections.observableArrayList(
        new BarChart.Series("Apples", FXCollections.observableArrayList(
           new BarChart.Data(years[0], 567d),
           new BarChart.Data(years[1], 1292d),
           new BarChart.Data(years[2], 1292d)
        )),
        new BarChart.Series("Lemons", FXCollections.observableArrayList(
           new BarChart.Data(years[0], 956),
           new BarChart.Data(years[1], 1665),
           new BarChart.Data(years[2], 2559)
        )),
        new BarChart.Series("Oranges", FXCollections.observableArrayList(
           new BarChart.Data(years[0], 1154),
           new BarChart.Data(years[1], 1927),
           new BarChart.Data(years[2], 2774)
        ))
    );
    BarChart chart = new BarChart(xAxis, yAxis, barChartData, 25.0d);
    getChildren().add(chart);
}
 
Example #6
Source File: Renderer.java    From strangefx with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void renderMeasuredProbabilities(int[] results) {
    CategoryAxis xAxis = new CategoryAxis();
    NumberAxis yAxis = new NumberAxis();
    BarChart<String, Integer> barChart = new BarChart(xAxis, yAxis);
    barChart.setData(getChartData(results));
    barChart.setTitle("Measured probability distribution");
    StackPane root = new StackPane();
    root.getChildren().add(barChart);
    if (myStage != null) {
        Scene oldscene = myStage.getScene();
        VBox box = (VBox)(oldscene.getRoot());
        oldscene.setRoot(new StackPane());
        box.getChildren().add(root);
        Scene newScene = new Scene(box);
        newScene.getStylesheets().add(Main.class.getResource("/styles.css").toExternalForm());
        myStage.setScene(newScene);
    } else {
        Stage stage = new Stage();
        stage.setScene(new Scene(root, 640, 480));
        stage.show();
    }

}
 
Example #7
Source File: WordFrequencyApp.java    From FXTutorials with MIT License 6 votes vote down vote up
private Parent createContent() {
    StackPane root = new StackPane();
    root.setPrefSize(800, 600);

    BarChart<String, Number> chart = new BarChart<>(new CategoryAxis(), new NumberAxis());

    XYChart.Series<String, Number> series = new XYChart.Series<>();

    extractor.extract()
            .stream()
            .sorted((e1, e2) -> e2.getFrequency() - e1.getFrequency())
            .limit(10)
            .forEach(entry -> {
                series.getData().add(new XYChart.Data<>(entry.getWord(), entry.getFrequency()));
            });

    chart.getData().add(series);

    root.getChildren().add(chart);

    return root;
}
 
Example #8
Source File: ChartAudioBar.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected BarChart<String, Number> createChart() {
    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis(0,50,10);
    final BarChart<String,Number> bc = new BarChart<String,Number>(xAxis,yAxis);
    bc.setId("barAudioDemo");
    bc.setLegendVisible(false);
    bc.setAnimated(false);
    bc.setBarGap(0);
    bc.setCategoryGap(1);
    bc.setVerticalGridLinesVisible(false);
    // setup chart
    bc.setTitle("Live Audio Spectrum Data");
    xAxis.setLabel("Frequency Bands");
    yAxis.setLabel("Magnitudes");
    yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis,null,"dB"));
    // add starting data
    XYChart.Series<String,Number> series1 = new XYChart.Series<String,Number>();
    series1.setName("Data Series 1");
    //noinspection unchecked
    series1Data = new XYChart.Data[128];
    String[] categories = new String[128];
    for (int i=0; i<series1Data.length; i++) {
        categories[i] = Integer.toString(i+1);
        series1Data[i] = new XYChart.Data<String,Number>(categories[i],50);
        series1.getData().add(series1Data[i]);
    }
    bc.getData().add(series1);
    return bc;
}
 
Example #9
Source File: ChartAdvancedBar.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected BarChart<String, Number> createChart() {
    final String[] years = {"2007", "2008", "2009"};
    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis();
    yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis,"$",null));
    final BarChart<String,Number> bc = new BarChart<String,Number>(xAxis,yAxis);
    // setup chart
    bc.setTitle("Advanced Bar Chart");
    xAxis.setLabel("Year");
    xAxis.setCategories(FXCollections.<String>observableArrayList(Arrays.asList(years)));
    yAxis.setLabel("Price");
    // add starting data
    XYChart.Series<String,Number> series1 = new XYChart.Series<String,Number>();
    series1.setName("Data Series 1");
    XYChart.Series<String,Number> series2 = new XYChart.Series<String,Number>();
    series2.setName("Data Series 2");
    XYChart.Series<String,Number> series3 = new XYChart.Series<String,Number>();
    series3.setName("Data Series 3");
    // create sample data
    series1.getData().add(new XYChart.Data<String,Number>(years[0], 567));
    series1.getData().add(new XYChart.Data<String,Number>(years[1], 1292));
    series1.getData().add(new XYChart.Data<String,Number>(years[2], 2180));
    series2.getData().add(new XYChart.Data<String,Number>(years[0], 956));
    series2.getData().add(new XYChart.Data<String,Number>(years[1], 1665));
    series2.getData().add(new XYChart.Data<String,Number>(years[2], 2450));
    series3.getData().add(new XYChart.Data<String,Number>(years[0], 800));
    series3.getData().add(new XYChart.Data<String,Number>(years[1], 1000));
    series3.getData().add(new XYChart.Data<String,Number>(years[2], 2800));
    bc.getData().add(series1);
    bc.getData().add(series2);
    bc.getData().add(series3);
    return bc;
}
 
Example #10
Source File: SampleTableModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ObservableList<BarChart.Series> getBarChartData() {
    if (bcData == null) {
        bcData = FXCollections.<BarChart.Series>observableArrayList();
        for (int row = 0; row < getRowCount(); row++) {
            ObservableList<BarChart.Data> series = FXCollections.<BarChart.Data>observableArrayList();
            for (int column = 0; column < getColumnCount(); column++) {
                series.add(new BarChart.Data(getColumnName(column), getValueAt(row, column)));
            }
            bcData.add(new BarChart.Series(series));
        }
    }
    return bcData;
}
 
Example #11
Source File: SampleTableModel.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public ObservableList<BarChart.Series> getBarChartData() {
    if (bcData == null) {
        bcData = FXCollections.<BarChart.Series>observableArrayList();
        for (int row = 0; row < getRowCount(); row++) {
            ObservableList<BarChart.Data> series = FXCollections.<BarChart.Data>observableArrayList();
            for (int column = 0; column < getColumnCount(); column++) {
                series.add(new BarChart.Data(getColumnName(column), getValueAt(row, column)));
            }
            bcData.add(new BarChart.Series(series));
        }
    }
    return bcData;
}
 
Example #12
Source File: SwingInterop.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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);
    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;
}
 
Example #13
Source File: BarCharts - MainApp.java    From Java-for-Data-Science with MIT License 5 votes vote down vote up
public void simpleBarChartByCountry(Stage stage) {
    stage.setTitle("Bar Chart");
    final BarChart<String, Number> barChart
            = new BarChart<>(xAxis, yAxis);
    barChart.setTitle("Country Summary");
    xAxis.setLabel("Country");
    yAxis.setLabel("Population");

    series1.setName("1950");
    addDataItem(series1, belgium, 8639369);
    addDataItem(series1, france, 42518000);
    addDataItem(series1, germany, 68374572);
    addDataItem(series1, netherlands, 10113527);
    addDataItem(series1, sweden, 7014005);
    addDataItem(series1, unitedKingdom, 50127000);

    series2.setName("1960");
    addDataItem(series2, belgium, 9118700);
    addDataItem(series2, france, 46584000);
    addDataItem(series2, germany, 72480869);
    addDataItem(series2, netherlands, 11486000);
    addDataItem(series2, sweden, 7480395);
    addDataItem(series2, unitedKingdom, 52372000);

    series3.setName("1970");
    addDataItem(series3, belgium, 9637800);
    addDataItem(series3, france, 51918000);
    addDataItem(series3, germany, 77783164);
    addDataItem(series3, netherlands, 13032335);
    addDataItem(series3, sweden, 8042803);
    addDataItem(series3, unitedKingdom, 55632000);

    Scene scene = new Scene(barChart, 800, 600);
    barChart.getData().addAll(series1, series2, series3);
    stage.setScene(scene);
    stage.show();
}
 
Example #14
Source File: AdvBarAudioChartSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
protected BarChart<String, Number> createChart() {
    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis(0,50,10);
    final BarChart<String,Number> bc = new BarChart<String,Number>(xAxis,yAxis);
    bc.setId("barAudioDemo");
    bc.setLegendVisible(false);
    bc.setAnimated(false);
    bc.setBarGap(0);
    bc.setCategoryGap(1);
    bc.setVerticalGridLinesVisible(false);
    // setup chart
    bc.setTitle("Live Audio Spectrum Data");
    xAxis.setLabel("Frequency Bands");
    yAxis.setLabel("Magnitudes");
    yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis,null,"dB"));
    // add starting data
    XYChart.Series<String,Number> series1 = new XYChart.Series<String,Number>();
    series1.setName("Data Series 1");
    //noinspection unchecked
    series1Data = new XYChart.Data[128];
    String[] categories = new String[128];
    for (int i=0; i<series1Data.length; i++) {
        categories[i] = Integer.toString(i+1);
        series1Data[i] = new XYChart.Data<String,Number>(categories[i],50);
        series1.getData().add(series1Data[i]);
    }
    bc.getData().add(series1);
    return bc;
}
 
Example #15
Source File: InfluenceAnalysisUI.java    From SONDY with GNU General Public License v3.0 5 votes vote down vote up
public final void initializeRankDistributionChart(){
    xAxis = new CategoryAxis();
    yAxis = new NumberAxis();
    xAxis.setLabel("Rank");
    xAxis.setTickLength(5);
    yAxis.setTickLabelsVisible(false);
    yAxis.setTickMarkVisible(false);
    rankDistributionChart = new BarChart(xAxis,yAxis);
    rankDistributionChart.setLegendVisible(false);
    UIUtils.setSize(rankDistributionChart, Main.columnWidthRIGHT+5, 300);
    rankDistributionChart.setCategoryGap(0);
}
 
Example #16
Source File: AdvancedBarChartSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
protected BarChart<String, Number> createChart() {
    final String[] years = {"2007", "2008", "2009"};
    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis();
    yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis,"$",null));
    final BarChart<String,Number> bc = new BarChart<String,Number>(xAxis,yAxis);
    // setup chart
    bc.setTitle("Advanced Bar Chart");
    xAxis.setLabel("Year");
    xAxis.setCategories(FXCollections.<String>observableArrayList(Arrays.asList(years)));
    yAxis.setLabel("Price");
    // add starting data
    XYChart.Series<String,Number> series1 = new XYChart.Series<String,Number>();
    series1.setName("Data Series 1");
    XYChart.Series<String,Number> series2 = new XYChart.Series<String,Number>();
    series2.setName("Data Series 2");
    XYChart.Series<String,Number> series3 = new XYChart.Series<String,Number>();
    series3.setName("Data Series 3");
    // create sample data
    series1.getData().add(new XYChart.Data<String,Number>(years[0], 567));
    series1.getData().add(new XYChart.Data<String,Number>(years[1], 1292));
    series1.getData().add(new XYChart.Data<String,Number>(years[2], 2180));
    series2.getData().add(new XYChart.Data<String,Number>(years[0], 956));
    series2.getData().add(new XYChart.Data<String,Number>(years[1], 1665));
    series2.getData().add(new XYChart.Data<String,Number>(years[2], 2450));
    series3.getData().add(new XYChart.Data<String,Number>(years[0], 800));
    series3.getData().add(new XYChart.Data<String,Number>(years[1], 1000));
    series3.getData().add(new XYChart.Data<String,Number>(years[2], 2800));
    bc.getData().add(series1);
    bc.getData().add(series2);
    bc.getData().add(series3);
    return bc;
}
 
Example #17
Source File: BarChartBuilderService.java    From AsciidocFX with Apache License 2.0 5 votes vote down vote up
@Override
protected XYChart<String, Number> createXYChart() {
    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis();
    final XYChart<String, Number> chart = new BarChart<String, Number>(xAxis, yAxis);
    chart.getStyleClass().add("chart-extension");
    return chart;
}
 
Example #18
Source File: AdvHorizontalBarChartSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
protected BarChart<Number, String> createChart() {
    final String[] years = {"2007", "2008", "2009"};
    final CategoryAxis yAxis = new CategoryAxis();
    final NumberAxis xAxis = new NumberAxis();
    final BarChart<Number,String> bc = new BarChart<Number,String>(xAxis,yAxis);
    // setup chart
    bc.setTitle("Horizontal Bar Chart Example");
    yAxis.setLabel("Year");
    yAxis.setCategories(FXCollections.<String>observableArrayList(Arrays.asList(years)));
    xAxis.setLabel("Price");
    // add starting data
    XYChart.Series<Number,String> series1 = new XYChart.Series<Number,String>();
    series1.setName("Data Series 1");
    XYChart.Series<Number,String> series2 = new XYChart.Series<Number,String>();
    series2.setName("Data Series 2");
    XYChart.Series<Number,String> series3 = new XYChart.Series<Number,String>();
    series3.setName("Data Series 3");
    series1.getData().add(new XYChart.Data<Number,String>(567, years[0]));
    series1.getData().add(new XYChart.Data<Number,String>(1292, years[1]));
    series1.getData().add(new XYChart.Data<Number,String>(2180, years[2]));
    series2.getData().add(new XYChart.Data<Number,String>(956, years[0]));
    series2.getData().add(new XYChart.Data<Number,String>(1665, years[1]));
    series2.getData().add(new XYChart.Data<Number,String>(2450, years[2]));
    series3.getData().add(new XYChart.Data<Number,String>(800, years[0]));
    series3.getData().add(new XYChart.Data<Number,String>(1000, years[1]));
    series3.getData().add(new XYChart.Data<Number,String>(2800, years[2]));
    bc.getData().add(series1);
    bc.getData().add(series2);
    bc.getData().add(series3);
    return bc;
}
 
Example #19
Source File: Main.java    From quantumjava with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void showResults(int[] results) {
    CategoryAxis xAxis = new CategoryAxis();
    NumberAxis yAxis = new NumberAxis();
    BarChart<String, Integer> barChart = new BarChart(xAxis, yAxis);
    barChart.setData(getChartData(results));
    barChart.setTitle("Classic probability distribution");
    StackPane root = new StackPane();
    root.getChildren().add(barChart);
    Stage stage = new Stage();
    stage.setTitle("Two coins, classic case");
    stage.setScene(new Scene(root, 640, 480));
    stage.show();
}
 
Example #20
Source File: SwingInterop.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
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);
    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;
}
 
Example #21
Source File: AdvBarAudioChartSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
protected BarChart<String, Number> createChart() {
    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis(0,50,10);
    final BarChart<String,Number> bc = new BarChart<String,Number>(xAxis,yAxis);
    bc.setId("barAudioDemo");
    bc.setLegendVisible(false);
    bc.setAnimated(false);
    bc.setBarGap(0);
    bc.setCategoryGap(1);
    bc.setVerticalGridLinesVisible(false);
    // setup chart
    bc.setTitle("Live Audio Spectrum Data");
    xAxis.setLabel("Frequency Bands");
    yAxis.setLabel("Magnitudes");
    yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis,null,"dB"));
    // add starting data
    XYChart.Series<String,Number> series1 = new XYChart.Series<String,Number>();
    series1.setName("Data Series 1");
    //noinspection unchecked
    series1Data = new XYChart.Data[128];
    String[] categories = new String[128];
    for (int i=0; i<series1Data.length; i++) {
        categories[i] = Integer.toString(i+1);
        series1Data[i] = new XYChart.Data<String,Number>(categories[i],50);
        series1.getData().add(series1Data[i]);
    }
    bc.getData().add(series1);
    return bc;
}
 
Example #22
Source File: AdvancedBarChartSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
protected BarChart<String, Number> createChart() {
    final String[] years = {"2007", "2008", "2009"};
    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis();
    yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis,"$",null));
    final BarChart<String,Number> bc = new BarChart<String,Number>(xAxis,yAxis);
    // setup chart
    bc.setTitle("Advanced Bar Chart");
    xAxis.setLabel("Year");
    xAxis.setCategories(FXCollections.<String>observableArrayList(Arrays.asList(years)));
    yAxis.setLabel("Price");
    // add starting data
    XYChart.Series<String,Number> series1 = new XYChart.Series<String,Number>();
    series1.setName("Data Series 1");
    XYChart.Series<String,Number> series2 = new XYChart.Series<String,Number>();
    series2.setName("Data Series 2");
    XYChart.Series<String,Number> series3 = new XYChart.Series<String,Number>();
    series3.setName("Data Series 3");
    // create sample data
    series1.getData().add(new XYChart.Data<String,Number>(years[0], 567));
    series1.getData().add(new XYChart.Data<String,Number>(years[1], 1292));
    series1.getData().add(new XYChart.Data<String,Number>(years[2], 2180));
    series2.getData().add(new XYChart.Data<String,Number>(years[0], 956));
    series2.getData().add(new XYChart.Data<String,Number>(years[1], 1665));
    series2.getData().add(new XYChart.Data<String,Number>(years[2], 2450));
    series3.getData().add(new XYChart.Data<String,Number>(years[0], 800));
    series3.getData().add(new XYChart.Data<String,Number>(years[1], 1000));
    series3.getData().add(new XYChart.Data<String,Number>(years[2], 2800));
    bc.getData().add(series1);
    bc.getData().add(series2);
    bc.getData().add(series3);
    return bc;
}
 
Example #23
Source File: AdvHorizontalBarChartSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
protected BarChart<Number, String> createChart() {
    final String[] years = {"2007", "2008", "2009"};
    final CategoryAxis yAxis = new CategoryAxis();
    final NumberAxis xAxis = new NumberAxis();
    final BarChart<Number,String> bc = new BarChart<Number,String>(xAxis,yAxis);
    // setup chart
    bc.setTitle("Horizontal Bar Chart Example");
    yAxis.setLabel("Year");
    yAxis.setCategories(FXCollections.<String>observableArrayList(Arrays.asList(years)));
    xAxis.setLabel("Price");
    // add starting data
    XYChart.Series<Number,String> series1 = new XYChart.Series<Number,String>();
    series1.setName("Data Series 1");
    XYChart.Series<Number,String> series2 = new XYChart.Series<Number,String>();
    series2.setName("Data Series 2");
    XYChart.Series<Number,String> series3 = new XYChart.Series<Number,String>();
    series3.setName("Data Series 3");
    series1.getData().add(new XYChart.Data<Number,String>(567, years[0]));
    series1.getData().add(new XYChart.Data<Number,String>(1292, years[1]));
    series1.getData().add(new XYChart.Data<Number,String>(2180, years[2]));
    series2.getData().add(new XYChart.Data<Number,String>(956, years[0]));
    series2.getData().add(new XYChart.Data<Number,String>(1665, years[1]));
    series2.getData().add(new XYChart.Data<Number,String>(2450, years[2]));
    series3.getData().add(new XYChart.Data<Number,String>(800, years[0]));
    series3.getData().add(new XYChart.Data<Number,String>(1000, years[1]));
    series3.getData().add(new XYChart.Data<Number,String>(2800, years[2]));
    bc.getData().add(series1);
    bc.getData().add(series2);
    bc.getData().add(series3);
    return bc;
}
 
Example #24
Source File: SampleTableModel.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public ObservableList<BarChart.Series> getBarChartData() {
    if (bcData == null) {
        bcData = FXCollections.<BarChart.Series>observableArrayList();
        for (int row = 0; row < getRowCount(); row++) {
            ObservableList<BarChart.Data> series = FXCollections.<BarChart.Data>observableArrayList();
            for (int column = 0; column < getColumnCount(); column++) {
                series.add(new BarChart.Data(getColumnName(column), getValueAt(row, column)));
            }
            bcData.add(new BarChart.Series(series));
        }
    }
    return bcData;
}
 
Example #25
Source File: AreaBarChart.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public AreaBarChart(@Nonnull ModularFeatureListRow row, AtomicDouble progress) {
  XYChart.Series data = new XYChart.Series();
  int i = 1;
  int size = row.getFeatures().size();
  for (Entry<RawDataFile, ModularFeature> entry : row.getFeatures().entrySet()) {
    Property<Float> areaProperty = entry.getValue().get(AreaType.class);
    data.getData().add(
        new XYChart.Data("" + i, areaProperty.getValue() == null ? 0f : areaProperty.getValue()));
    i++;
    if (progress != null)
      progress.addAndGet(1.0 / size);
  }

  final CategoryAxis xAxis = new CategoryAxis();
  final NumberAxis yAxis = new NumberAxis();
  final BarChart<String, Number> bc = new BarChart<String, Number>(xAxis, yAxis);
  bc.setLegendVisible(false);
  bc.setMinHeight(100);
  bc.setPrefHeight(100);
  bc.setMaxHeight(100);
  bc.setBarGap(3);
  bc.setCategoryGap(3);
  bc.setPrefWidth(150);

  bc.getData().addAll(data);
  this.getChildren().add(bc);
}
 
Example #26
Source File: MainWindow.java    From quantumjava with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void start(Stage stage) throws Exception {
    int results[] = TwoCoins.calculate(count);
    CategoryAxis xAxis = new CategoryAxis();
    NumberAxis yAxis = new NumberAxis();
    BarChart<String, Integer> barChart = new BarChart(xAxis, yAxis);
    barChart.setData(getChartData(results));
    StackPane root = new StackPane();
    root.getChildren().add(barChart);
    stage.setScene(new Scene(root, 640, 480));
    stage.show();
}
 
Example #27
Source File: BarCharts - MainApp.java    From Java-for-Data-Science with MIT License 4 votes vote down vote up
public void simpleBarChartByYear(Stage stage) {
    stage.setTitle("Bar Chart");
    final BarChart<String, Number> barChart
            = new BarChart<>(xAxis, yAxis);
    barChart.setTitle("Year Summary");
    xAxis.setLabel("Year");
    yAxis.setLabel("Population");

    String year1950 = "1950";
    String year1960 = "1960";
    String year1970 = "1970";

    series1.setName(belgium);
    addDataItem(series1, year1950, 8639369);
    addDataItem(series1, year1960, 9118700);
    addDataItem(series1, year1970, 9637800);

    series2.setName(france);
    addDataItem(series2, year1950, 42518000);
    addDataItem(series2, year1960, 46584000);
    addDataItem(series2, year1970, 51918000);

    series3.setName(germany);
    addDataItem(series3, year1950, 68374572);
    addDataItem(series3, year1960, 72480869);
    addDataItem(series3, year1970, 77783164);

    series4.setName(netherlands);
    addDataItem(series4, year1950, 10113527);
    addDataItem(series4, year1960, 11486000);
    addDataItem(series4, year1970, 13032335);

    series5.setName(sweden);
    addDataItem(series5, year1950, 7014005);
    addDataItem(series5, year1960, 7480395);
    addDataItem(series5, year1970, 8042803);

    series6.setName(unitedKingdom);
    addDataItem(series6, year1950, 50127000);
    addDataItem(series6, year1960, 52372000);
    addDataItem(series6, year1970, 55632000);

    Scene scene = new Scene(barChart, 800, 600);
    barChart.getData().addAll(series1, series2, series3, series4, series5, series6);
    stage.setScene(scene);
    stage.show();
}
 
Example #28
Source File: FxmlControl.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public static void setBarChartColors(BarChart chart, List<String> palette,
        boolean showLegend) {
    if (chart == null || palette == null) {
        return;
    }
    List<XYChart.Series> seriesList = chart.getData();
    if (seriesList == null
            || seriesList.size() > palette.size()) {
        return;
    }
    for (int i = 0; i < seriesList.size(); i++) {
        XYChart.Series series = seriesList.get(i);
        if (series.getData() == null) {
            continue;
        }
        for (int j = 0; j < series.getData().size(); j++) {
            XYChart.Data item = (XYChart.Data) series.getData().get(j);
            if (item.getNode() != null) {
                String color = palette.get(i);
                item.getNode().setStyle("-fx-bar-fill: " + color + ";");
            }
        }
    }
    chart.setLegendVisible(showLegend);
    if (showLegend) {
        Set<Node> legendItems = chart.lookupAll("Label.chart-legend-item");
        if (legendItems.isEmpty()) {
            return;
        }
        for (Node legendItem : legendItems) {
            Label legendLabel = (Label) legendItem;
            Node legend = legendLabel.getGraphic();
            if (legend != null) {
                for (int i = 0; i < seriesList.size(); i++) {
                    if (seriesList.get(i).getName().equals(legendLabel.getText())) {
                        legend.setStyle("-fx-background-color: " + palette.get(i));
                        break;
                    }
                }
            }
        }
    }
}
 
Example #29
Source File: FxmlControl.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public static void setBarChartColors(BarChart chart, boolean showLegend) {
    List<String> palette = FxmlColor.randomColorsHex(chart.getData().size());
    setBarChartColors(chart, palette, showLegend);
}
 
Example #30
Source File: ImageAnalyseController.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public void showColorData(ColorComponent component,
        WebView view, BarChart barchart) {
    try {
        List<String> names = new ArrayList<>();
        names.addAll(Arrays.asList(message("Value"), message("PixelsNumber"),
                message("Percentage"), message("Color"),
                message("Red"), message("Green"), message("Blue"), message("Opacity"),
                message("Hue"), message("Brightness"), message("Saturation")
        ));
        StringTable table = new StringTable(names, message(component.name()), 3);
        long total = (long) (image.getWidth() * image.getHeight());
        int[] histogram = data.histogram(component);
        for (int i = histogram.length - 1; i >= 0; --i) {
            List<String> row = new ArrayList<>();
            java.awt.Color aColor = ImageStatistic.color(component, i);
            int red = aColor.getRed();
            int green = aColor.getGreen();
            int blue = aColor.getBlue();
            Color fColor = ImageColor.converColor(aColor);
            row.addAll(Arrays.asList(i + "", histogram[i] + "",
                    (int) (histogram[i] * 100 / total) + "%",
                    fColor.toString(), red + " ", green + " ", blue + " ",
                    (int) Math.round(fColor.getOpacity() * 100) + "%",
                    Math.round(fColor.getHue()) + " ",
                    Math.round(fColor.getSaturation() * 100) + "%",
                    Math.round(fColor.getBrightness() * 100) + "%"
            ));
            table.add(row);
        }
        final String html = StringTable.tableHtml(table);
        view.getEngine().loadContent​(html);

        XYChart.Series series = new XYChart.Series();
        for (int i = 0; i < histogram.length; ++i) {
            series.getData().add(new XYChart.Data(i + "", histogram[i]));
        }
        series.setName(message(component.name()));

        barchart.setAnimated(false);
        barchart.getData().clear();
        barchart.setAnimated(true);
        barchart.getXAxis().setAnimated(false);
        barchart.getData().add(series);
        String colorString = FxmlColor.rgb2Hex(ImageColor.color(component));
        for (Node n : barchart.lookupAll(".default-color0.chart-bar")) {
            n.setStyle("-fx-bar-fill: " + colorString + "; ");
        }
        barchart.setLegendVisible(false);

    } catch (Exception e) {
        logger.error(e.toString());
    }
}