Java Code Examples for javafx.scene.chart.BarChart#setLegendVisible()

The following examples show how to use javafx.scene.chart.BarChart#setLegendVisible() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
Source File: ParetoChartController.java    From OEE-Designer with MIT License 4 votes vote down vote up
private BarChart<String, Number> createBarChart(String categoryLabel) {
	// X-Axis category
	CategoryAxis xAxis = new CategoryAxis();
	xAxis.setLabel(categoryLabel);

	// Y-Axis (%)
	NumberAxis yAxis = new NumberAxis(0, 100, 10);
	yAxis.setLabel(DesignerLocalizer.instance().getLangString("percent"));
	yAxis.setAutoRanging(false);
	yAxis.setUpperBound(100.0d);
	yAxis.setLowerBound(0.0d);

	// create bar chart
	BarChart<String, Number> chBarChart = new BarChart<>(xAxis, yAxis);
	chBarChart.setTitle(chartTitle);
	chBarChart.setLegendVisible(false);
	chBarChart.setAnimated(false);
	chBarChart.getData().add(barChartSeries);

	// add the points
	double total = totalCount.doubleValue();

	if (total > 0.0d) {
		int count = 0;
		for (ParetoItem paretoItem : paretoItems) {
			if (count > TOP_N) {
				break;
			}
			count++;

			Float percentage = new Float(paretoItem.getValue().floatValue() / total * 100.0f);
			XYChart.Data<String, Number> point = new XYChart.Data<>(paretoItem.getCategory(), percentage);
			barChartSeries.getData().add(point);
		}
	}

	// add listener for mouse click on bar
	for (Series<String, Number> series : chBarChart.getData()) {
		for (XYChart.Data<String, Number> item : series.getData()) {

			item.getNode().setOnMouseClicked((MouseEvent event) -> {
				onBarChartNodeSelected(item);
			});
		}
	}

	return chBarChart;
}
 
Example 9
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;
                    }
                }
            }
        }
    }
}