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

The following examples show how to use javafx.scene.chart.LineChart#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: MenuController.java    From zest-writer with GNU General Public License v3.0 6 votes vote down vote up
private void displayIndex(Map<String, Double> resultIndex, String title, String header) {
    BaseDialog dialog = new BaseDialog(title, header);
    dialog.getDialogPane().setPrefSize(800, 600);
    dialog.getDialogPane().getButtonTypes().addAll(new ButtonType(Configuration.getBundle().getString("ui.actions.stats.close"), ButtonBar.ButtonData.CANCEL_CLOSE));

    // draw
    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis();
    final LineChart<String,Number> lineChart = new LineChart<>(xAxis, yAxis);
    lineChart.setTitle(title);
    lineChart.setLegendVisible(false);

    xAxis.setLabel(Configuration.getBundle().getString("ui.actions.stats.xaxis"));
    yAxis.setLabel(Configuration.getBundle().getString("ui.actions.readable.yaxis"));

    XYChart.Series<String, Number> series = new XYChart.Series();
    for(Map.Entry<String, Double> st:resultIndex.entrySet()) {
        series.getData().add(new XYChart.Data(st.getKey(), st.getValue()));
    }
    lineChart.getData().addAll(series);
    dialog.getDialogPane().setContent(lineChart);
    dialog.setResizable(true);
    dialog.showAndWait();
}
 
Example 2
Source File: MultipleAxesLineChart.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
public void addSeries(final XYChart.Series<Number, Number> series, final Color lineColor) {
    final NumberAxis yAxis = new NumberAxis();
    final NumberAxis xAxis = new NumberAxis();

    // style x-axis
    xAxis.setAutoRanging(false);
    xAxis.setVisible(false);
    xAxis.setOpacity(0.0); // somehow the upper setVisible does not work
    xAxis.lowerBoundProperty().bind(((NumberAxis) baseChart.getXAxis()).lowerBoundProperty());
    xAxis.upperBoundProperty().bind(((NumberAxis) baseChart.getXAxis()).upperBoundProperty());
    xAxis.tickUnitProperty().bind(((NumberAxis) baseChart.getXAxis()).tickUnitProperty());

    // style y-axis
    yAxis.setSide(Side.RIGHT);
    yAxis.setLabel(series.getName());

    // create chart
    final LineChart<Number, Number> lineChart = new LineChart<>(xAxis, yAxis);
    lineChart.setAnimated(false);
    lineChart.setLegendVisible(false);
    lineChart.getData().add(series);

    styleBackgroundChart(lineChart, lineColor);
    setFixedAxisWidth(lineChart);

    chartColorMap.put(lineChart, lineColor);
    backgroundCharts.add(lineChart);
}
 
Example 3
Source File: MultipleAxesLineChart.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
private void styleBaseChart(final LineChart<?, ?> baseChart) {
    baseChart.setCreateSymbols(false);
    baseChart.setLegendVisible(false);
    baseChart.getXAxis().setAutoRanging(false);
    baseChart.getXAxis().setAnimated(false);
    baseChart.getYAxis().setAnimated(false);
}
 
Example 4
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 5
Source File: AdvancedStockLineChartSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
protected LineChart<Number, Number> createChart() {
    xAxis = new NumberAxis(0,24,3);
    final NumberAxis yAxis = new NumberAxis(0,100,10);
    final LineChart<Number,Number> lc = new LineChart<Number,Number>(xAxis,yAxis);
    // setup chart
    lc.setId("lineStockDemo");
    lc.setCreateSymbols(false);
    lc.setAnimated(false);
    lc.setLegendVisible(false);
    lc.setTitle("ACME Company Stock");
    xAxis.setLabel("Time");
    xAxis.setForceZeroInRange(false);
    yAxis.setLabel("Share Price");
    yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis,"$",null));
    // add starting data
    hourDataSeries = new XYChart.Series<Number,Number>();
    hourDataSeries.setName("Hourly Data");
    minuteDataSeries = new XYChart.Series<Number,Number>();
    minuteDataSeries.setName("Minute Data");
    // create some starting data
    hourDataSeries.getData().add(new XYChart.Data<Number,Number>(timeInHours,prevY));
    minuteDataSeries.getData().add(new XYChart.Data<Number,Number>(timeInHours,prevY));
    for (double m=0; m<(60); m++) {
        nextTime();
        plotTime();
    }
    lc.getData().add(minuteDataSeries);
    lc.getData().add(hourDataSeries);
    return lc;
}
 
Example 6
Source File: AdvancedStockLineChartSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
protected LineChart<Number, Number> createChart() {
    xAxis = new NumberAxis(0,24,3);
    final NumberAxis yAxis = new NumberAxis(0,100,10);
    final LineChart<Number,Number> lc = new LineChart<Number,Number>(xAxis,yAxis);
    // setup chart
    lc.setId("lineStockDemo");
    lc.setCreateSymbols(false);
    lc.setAnimated(false);
    lc.setLegendVisible(false);
    lc.setTitle("ACME Company Stock");
    xAxis.setLabel("Time");
    xAxis.setForceZeroInRange(false);
    yAxis.setLabel("Share Price");
    yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis,"$",null));
    // add starting data
    hourDataSeries = new XYChart.Series<Number,Number>();
    hourDataSeries.setName("Hourly Data");
    minuteDataSeries = new XYChart.Series<Number,Number>();
    minuteDataSeries.setName("Minute Data");
    // create some starting data
    hourDataSeries.getData().add(new XYChart.Data<Number,Number>(timeInHours,prevY));
    minuteDataSeries.getData().add(new XYChart.Data<Number,Number>(timeInHours,prevY));
    for (double m=0; m<(60); m++) {
        nextTime();
        plotTime();
    }
    lc.getData().add(minuteDataSeries);
    lc.getData().add(hourDataSeries);
    return lc;
}
 
Example 7
Source File: ChartAdvancedStockLine.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected LineChart<Number, Number> createChart() {
    xAxis = new NumberAxis(0,24,3);
    final NumberAxis yAxis = new NumberAxis(0,100,10);
    final LineChart<Number,Number> lc = new LineChart<Number,Number>(xAxis,yAxis);
    // setup chart
    lc.setId("lineStockDemo");
    lc.setCreateSymbols(false);
    lc.setAnimated(false);
    lc.setLegendVisible(false);
    lc.setTitle("ACME Company Stock");
    xAxis.setLabel("Time");
    xAxis.setForceZeroInRange(false);
    yAxis.setLabel("Share Price");
    yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis,"$",null));
    // add starting data
    hourDataSeries = new XYChart.Series<Number,Number>();
    hourDataSeries.setName("Hourly Data");
    minuteDataSeries = new XYChart.Series<Number,Number>();
    minuteDataSeries.setName("Minute Data");
    // create some starting data
    hourDataSeries.getData().add(new XYChart.Data<Number,Number>(timeInHours,prevY));
    minuteDataSeries.getData().add(new XYChart.Data<Number,Number>(timeInHours,prevY));
    for (double m=0; m<(60); m++) {
        nextTime();
        plotTime();
    }
    lc.getData().add(minuteDataSeries);
    lc.getData().add(hourDataSeries);
    return lc;
}
 
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: 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);
      }
    }
  };
}