Java Code Examples for javafx.scene.chart.NumberAxis#setUpperBound()

The following examples show how to use javafx.scene.chart.NumberAxis#setUpperBound() . 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: ParetoChartController.java    From OEE-Designer with MIT License 5 votes vote down vote up
private LineChart<String, Number> createLineChart(String categoryLabel) {
	// X-Axis category (not shown)
	CategoryAxis xAxis = new CategoryAxis();
	xAxis.setLabel(categoryLabel);
	xAxis.setOpacity(0);

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

	// create the line chart
	LineChart<String, Number> chLineChart = new LineChart<>(xAxis, yAxis);
	chLineChart.setTitle(chartTitle);
	chLineChart.setLegendVisible(false);
	chLineChart.setAnimated(false);
	chLineChart.setCreateSymbols(true);
	chLineChart.getData().add(lineChartSeries);

	// plot the points
	double total = totalCount.doubleValue();
	Float cumulative = new Float(0f);

	for (ParetoItem paretoItem : this.paretoItems) {
		cumulative += new Float(paretoItem.getValue().floatValue() / total * 100.0f);
		XYChart.Data<String, Number> point = new XYChart.Data<>(paretoItem.getCategory(), cumulative);
		lineChartSeries.getData().add(point);
	}

	return chLineChart;
}
 
Example 2
Source File: ChartUtil.java    From DevToolBox with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void changeChart(LineChart chart, Date now, Double dt, String name) {
    ObservableList<XYChart.Series> data = chart.getData();
    XYChart.Series xys = null;
    if (data.isEmpty()) {
        xys = getSeries(chart, dt, name);
        data.add(xys);
        addClickListener(chart);
    } else {
        boolean exits = false;
        for (XYChart.Series series : data) {
            if (name.equals(series.getName())) {
                exits = true;
                xys = series;
                break;
            }
        }
        if (!exits) {
            xys = getSeries(chart, dt, name);
            data.add(xys);
            addClickListener(chart);
        }
        NumberAxis na = (NumberAxis) chart.getYAxis();
        na.setUpperBound(Math.max(na.getUpperBound(), dt));
    }
    XYChart.Data xdata = new XYChart.Data<>(DATE_FORMAT.format(now), dt);
    xdata.setNode(new HoveredThresholdNode(dt, dt));
    xdata.getNode().setVisible(CACHE.get(name) == null ? true : CACHE.get(name));
    xys.getData().add(xdata);
    if (xys.getData().size() > 9) {
        xys.getData().remove(0);
    }
}
 
Example 3
Source File: LRInspectorController.java    From megan-ce with GNU General Public License v3.0 5 votes vote down vote up
/**
 * create a horizontal axis
 *
 * @param maxReadLength
 * @return axis
 */
private static Pane createAxis(final ReadOnlyIntegerProperty maxReadLength, final ReadOnlyDoubleProperty widthProperty) {
    final Pane pane = new Pane();
    pane.prefWidthProperty().bind(widthProperty);

    final NumberAxis axis = new NumberAxis();
    axis.setSide(Side.TOP);
    axis.setAutoRanging(false);
    axis.setLowerBound(0);
    axis.prefHeightProperty().set(20);
    axis.prefWidthProperty().bind(widthProperty.subtract(60));
    axis.setTickLabelFont(Font.font("Arial", 10));

    final ChangeListener<Number> changeListener = (observable, oldValue, newValue) -> {
        int minX = Math.round(maxReadLength.get() / 2000.0f); // at most 2000 major ticks
        for (int x = 10; x < 10000000; x *= 10) {
            if (x >= minX && widthProperty.doubleValue() * x >= 50 * maxReadLength.doubleValue()) {
                axis.setUpperBound(maxReadLength.get());
                axis.setTickUnit(x);
                return;
            }
        }
        axis.setTickUnit(maxReadLength.get());
        axis.setUpperBound(maxReadLength.get());
    };

    maxReadLength.addListener(changeListener);
    widthProperty.addListener(changeListener);

    pane.getChildren().add(axis);
    return pane;
}
 
Example 4
Source File: TrainingView.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Chart createChart(Series<Integer, Double> series) {
    NumberAxis xAxis = new NumberAxis();
    xAxis.setUpperBound(620d);
    xAxis.setMinorTickCount(25);
    xAxis.setTickUnit(100);
    xAxis.setAutoRanging(false);
    NumberAxis yAxis = new NumberAxis();
    LineChart answer = new LineChart(xAxis, yAxis);
    answer.setTitle("score evolution");
    answer.setCreateSymbols(false);
    ObservableList<XYChart.Series<Integer, Double>> data = FXCollections.observableArrayList();
    data.add(series);
    answer.setData(data);
    return answer;
}
 
Example 5
Source File: BreakingNewsDemoView.java    From htm.java-examples with GNU Affero General Public License v3.0 5 votes vote down vote up
public LineChart<String, Number> createChart(LabelledRadiusPane pane) {
    CategoryAxis xAxis = new CategoryAxis();
    NumberAxis yAxis = new NumberAxis();
    
    chart = new LineChart<>(xAxis, yAxis);
    chart.setTitle("Tweet Trend Analysis");
    chart.setCreateSymbols(false);
    chart.setLegendVisible(false);

    xAxis.setLabel("Time of Tweet");
    yAxis.setUpperBound(1.0);
    yAxis.setLowerBound(0.0);
    yAxis.setLabel("Anomaly\n  Score");
    yAxis.setForceZeroInRange(true);
    
    series = new XYChart.Series<>();
    series.setName("Tweet Data");
    chart.getData().add(series);
    chartSeriesProperty.set(series);
    
    Node line = series.getNode().lookup(".chart-series-line");
    line.setStyle("-fx-stroke: rgb(20, 164, 220)");
    
    chart.setPrefWidth(1200);
    chart.setPrefHeight(275);
    chart.setLayoutY(pane.labelHeightProperty().get() + 10);
    
    return chart;
}
 
Example 6
Source File: AxisInlierUtils.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
private static void applyRange(NumberAxis axis, int maxNumberOfTicks, Tuple2<Double, Double> bounds) {
    var boundsWidth = getBoundsWidth(bounds);
    if (boundsWidth < 0) {
        throw new IllegalArgumentException(
                "The lower bound must be a smaller number than the upper bound");
    }
    if (boundsWidth == 0 || Double.isNaN(boundsWidth)) {
        // less than 2 unique data-points: recalculating axis range doesn't make sense
        return;
    }

    axis.setAutoRanging(false);

    var lowerBound = bounds.first;
    var upperBound = bounds.second;

    // If one of the ends of the range weren't zero,
    // additional logic would be needed to make ticks "round".
    // Of course, many, if not most, charts benefit from having 0 on the axis.
    if (lowerBound > 0) {
        lowerBound = 0d;
    } else if (upperBound < 0) {
        upperBound = 0d;
    }

    axis.setLowerBound(lowerBound);
    axis.setUpperBound(upperBound);

    var referenceTickUnit = computeReferenceTickUnit(maxNumberOfTicks, bounds);

    var tickUnit = computeTickUnit(referenceTickUnit);

    axis.setTickUnit(tickUnit);
}
 
Example 7
Source File: MainDialog.java    From bandit with Apache License 2.0 5 votes vote down vote up
private void resetTest(int numDraws, List<LineChart<Number, Number>> charts) {
    for (LineChart<Number, Number> chart : charts) {
        chart.getData().clear();
        NumberAxis xAxis = (NumberAxis) chart.getXAxis();
        xAxis.setUpperBound(numDraws);
        xAxis.setTickUnit(numDraws / 10);
    }

    algorithms.forEach(BanditAlgorithm::reset);
}
 
Example 8
Source File: FeatureShapeChart.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public FeatureShapeChart(@Nonnull ModularFeatureListRow row, AtomicDouble progress) {
  try {
    final NumberAxis xAxis = new NumberAxis();
    final NumberAxis yAxis = new NumberAxis();
    final LineChart<Number, Number> bc = new LineChart<>(xAxis, yAxis);

    DataPoint max = null;
    double maxRT = 0;
    int size = row.getFeatures().size();
    int fi = 0;
    for (ModularFeature f : row.getFeatures().values()) {
      XYChart.Series<Number, Number> data = new XYChart.Series<>();
      List<Integer> scans = f.getScanNumbers();
      List<DataPoint> dps = f.getDataPoints();
      RawDataFile raw = f.getRawDataFile();
      // add data points retention time -> intensity
      for (int i = 0; i < scans.size(); i++) {
        DataPoint dp = dps.get(i);
        double retentionTime = raw.getScan(scans.get(i)).getRetentionTime();
        double intensity = dp == null ? 0 : dp.getIntensity();
        data.getData().add(new XYChart.Data<>(retentionTime, intensity));
        if (dp != null && (max == null || max.getIntensity() < dp.getIntensity())) {
          max = dp;
          maxRT = retentionTime;
        }
        if (progress != null)
          progress.addAndGet(1.0 / size / scans.size());
      }
      fi++;
      bc.getData().add(data);
      if (progress != null)
        progress.set((double) fi / size);
    }

    bc.setLegendVisible(false);
    bc.setMinHeight(100);
    bc.setPrefHeight(100);
    bc.setMaxHeight(100);
    bc.setPrefWidth(150);
    bc.setCreateSymbols(false);

    // do not add data to chart
    xAxis.setAutoRanging(false);
    xAxis.setUpperBound(maxRT + 1.5d);
    xAxis.setLowerBound(maxRT - 1.5d);

    bc.setOnScroll(new EventHandler<>() {
      @Override
      public void handle(ScrollEvent event) {
        NumberAxis axis = xAxis;
        final double minX = xAxis.getLowerBound();
        final double maxX = xAxis.getUpperBound();
        double d = maxX - minX;
        double x = event.getX();
        double direction = event.getDeltaY();
        if (direction > 0) {
          if (d > 0.3) {
            axis.setLowerBound(minX + 0.1);
            axis.setUpperBound(maxX - 0.1);
          }
        } else {
          axis.setLowerBound(minX - 0.1);
          axis.setUpperBound(maxX + 0.1);
        }
        event.consume();
      }
    });

    this.getChildren().add(bc);
  } catch (Exception ex) {
    logger.log(Level.WARNING, "error in DP", ex);
  }
}
 
Example 9
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 10
Source File: ChromatogramRenderer.java    From old-mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public TreeTableCell<FeatureTableRow, Object> call(TreeTableColumn<FeatureTableRow, Object> p) {
  return new TreeTableCell<FeatureTableRow, Object>() {
    @Override
    public void updateItem(Object object, boolean empty) {
      super.updateItem(object, empty);
      setStyle(
          "-fx-border-color: transparent -fx-table-cell-border-color -fx-table-cell-border-color transparent;");
      if (object == null) {
        setText(null);
      } else {

        Chromatogram chromatogram = (Chromatogram) object;

        ChromatographyInfo[] chromatographyInfoValues = chromatogram.getRetentionTimes();
        float[] intensityValues = chromatogram.getIntensityValues();
        int numOfDataPoints = chromatogram.getNumberOfDataPoints();

        // x-axis
        NumberAxis xAxis = new NumberAxis();
        xAxis.setTickLabelsVisible(false);
        xAxis.setOpacity(0);
        xAxis.setAutoRanging(false);
        xAxis.setLowerBound(chromatogram.getRtRange().lowerEndpoint().getRetentionTime());
        xAxis.setUpperBound(chromatogram.getRtRange().upperEndpoint().getRetentionTime());

        // y-axis
        NumberAxis yAxis = new NumberAxis();
        yAxis.setTickLabelsVisible(false);
        yAxis.setOpacity(0);

        // Chart line
        final LineChart<Number, Number> lineChart = new LineChart<Number, Number>(xAxis, yAxis);
        XYChart.Series series = new XYChart.Series();
        for (int i = 1; i < numOfDataPoints; i++) {
          series.getData().add(new XYChart.Data(chromatographyInfoValues[i].getRetentionTime(),
              intensityValues[i]));
        }

        // Chart
        lineChart.getData().addAll(series);
        lineChart.setLegendVisible(false);
        lineChart.setCreateSymbols(false);
        lineChart.setMinSize(0, 0);
        lineChart.setPrefHeight(75);
        lineChart.setPrefWidth(100);

        setGraphic(lineChart);
      }
    }
  };
}
 
Example 11
Source File: VisualizerPresenter.java    From HdrHistogramVisualizer with Apache License 2.0 4 votes vote down vote up
void initializePercentileChartAxes() {
    checkNotNull(percentileChart);
    final NumberAxis xAxis = (NumberAxis) percentileChart.getXAxis();
    xAxis.setAutoRanging(false);
    xAxis.setTickUnit(1); // log axis -> 10^x steps
    xAxis.setLowerBound(0);
    xAxis.setUpperBound(0);

    // Limit X range to max value to avoid empty space
    percentileChart.getData().addListener((ListChangeListener<XYChart.Series<Number, Number>>) c -> {
        double maxX = percentileChart.getData().stream()
                .flatMap(series -> series.getData().stream())
                .mapToDouble(point -> point.getXValue().doubleValue())
                .max()
                .orElse(0);
        xAxis.setUpperBound(maxX);
    });

    // Format labels such that e.g. 10^6 is shown as 6 nines
    xAxis.setTickLabelFormatter(new StringConverter<Number>() {
        @Override
        public String toString(Number object) {
            int intValue = object.intValue();
            if (object.doubleValue() > intValue)
                return ""; // Only label full 10^x steps
            switch (intValue) {
                case 0:
                    return "0%";
                case 1:
                    return "90%";
                case 2:
                    return "99%";
                default:
                    String percentile = "99.";
                    for (int i = 2; i < intValue; i++) {
                        percentile += "9";
                    }
                    return percentile + "%";
            }

        }

        @Override
        public Number fromString(String string) {
            return null;
        }
    });
}