Java Code Examples for org.jfree.chart.plot.XYPlot#setRangeCrosshairPaint()

The following examples show how to use org.jfree.chart.plot.XYPlot#setRangeCrosshairPaint() . 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: EStandardChartTheme.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public void applyToCrosshair(@Nonnull JFreeChart chart) {
  XYPlot p = chart.getXYPlot();
  p.setDomainCrosshairPaint(DEFAULT_CROSS_HAIR_COLOR);
  p.setRangeCrosshairPaint(DEFAULT_CROSS_HAIR_COLOR);
  p.setDomainCrosshairStroke(DEFAULT_CROSS_HAIR_STROKE);
  p.setRangeCrosshairStroke(DEFAULT_CROSS_HAIR_STROKE);
  p.setDomainCrosshairVisible(DEFAULT_CROSS_HAIR_VISIBLE);
  p.setRangeCrosshairVisible(DEFAULT_CROSS_HAIR_VISIBLE);
}
 
Example 2
Source File: KendrickMassPlotTask.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * create 2D Kendrick mass plot
 */
private JFreeChart create2DKendrickMassPlot() {

  if (zAxisLabel.equals("none")) {
    logger.info("Creating new 2D chart instance");
    appliedSteps++;

    // load dataset
    dataset2D = new KendrickMassPlotXYDataset(parameters);

    // create chart
    chart = ChartFactory.createScatterPlot(title, xAxisLabel, yAxisLabel, dataset2D,
        PlotOrientation.VERTICAL, true, true, true);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainCrosshairPaint(Color.GRAY);
    plot.setRangeCrosshairPaint(Color.GRAY);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    appliedSteps++;

    // set axis
    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    NumberAxis range = (NumberAxis) plot.getRangeAxis();
    range.setRange(0, 1);
    if (xAxisLabel.contains("KMD")) {
      domain.setRange(0, 1);
    }

    // set renderer
    XYBlockPixelSizeRenderer renderer = new XYBlockPixelSizeRenderer();

    // set tooltip generator
    ScatterPlotToolTipGenerator tooltipGenerator =
        new ScatterPlotToolTipGenerator(xAxisLabel, yAxisLabel, zAxisLabel, rows);
    renderer.setSeriesToolTipGenerator(0, tooltipGenerator);
    plot.setRenderer(renderer);

    // set item label generator
    NameItemLabelGenerator generator = new NameItemLabelGenerator(rows);
    renderer.setDefaultItemLabelGenerator(generator);
    renderer.setDefaultItemLabelsVisible(false);
    renderer.setDefaultItemLabelFont(legendFont);
    renderer.setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
        TextAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -45), true);
  }
  return chart;
}
 
Example 3
Source File: VanKrevelenDiagramTask.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * create 2D Van Krevelen Diagram chart
 */
private JFreeChart create2DVanKrevelenDiagram() {
  logger.info("Creating new 2D chart instance");
  appliedSteps++;

  // load dataset
  VanKrevelenDiagramXYDataset dataset2D = new VanKrevelenDiagramXYDataset(filteredRows);

  // create chart
  chart = ChartFactory.createScatterPlot(title, "O/C", "H/C", dataset2D, PlotOrientation.VERTICAL,
      true, true, false);

  XYPlot plot = (XYPlot) chart.getPlot();
  plot.setBackgroundPaint(Color.WHITE);
  plot.setDomainCrosshairPaint(Color.GRAY);
  plot.setRangeCrosshairPaint(Color.GRAY);
  plot.setDomainCrosshairVisible(true);
  plot.setRangeCrosshairVisible(true);
  appliedSteps++;

  // set renderer
  XYBlockPixelSizeRenderer renderer = new XYBlockPixelSizeRenderer();

  // calc block sizes
  double maxX = plot.getDomainAxis().getRange().getUpperBound();
  double maxY = plot.getRangeAxis().getRange().getUpperBound();

  renderer.setBlockWidth(0.001);
  renderer.setBlockHeight(renderer.getBlockWidth() / (maxX / maxY));

  // set tooltip generator
  ScatterPlotToolTipGenerator tooltipGenerator =
      new ScatterPlotToolTipGenerator("O/C", "H/C", zAxisLabel, filteredRows);
  renderer.setSeriesToolTipGenerator(0, tooltipGenerator);
  plot.setRenderer(renderer);

  // set item label generator
  NameItemLabelGenerator generator = new NameItemLabelGenerator(filteredRows);
  renderer.setDefaultItemLabelGenerator(generator);
  renderer.setDefaultItemLabelsVisible(false);
  renderer.setDefaultItemLabelFont(legendFont);
  renderer.setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
      TextAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -45), true);

  return chart;
}
 
Example 4
Source File: ChromatogramPlotWindowController.java    From old-mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
@FXML
public void initialize() {

  final JFreeChart chart = chartNode.getChart();
  final XYPlot plot = chart.getXYPlot();

  // Do not set colors and strokes dynamically. They are instead provided
  // by the dataset and configured in configureRenderer()
  plot.setDrawingSupplier(null);
  plot.setDomainGridlinePaint(JavaFXUtil.convertColorToAWT(gridColor));
  plot.setRangeGridlinePaint(JavaFXUtil.convertColorToAWT(gridColor));
  plot.setBackgroundPaint(JavaFXUtil.convertColorToAWT(backgroundColor));
  plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
  plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
  plot.setDomainCrosshairPaint(JavaFXUtil.convertColorToAWT(crossHairColor));
  plot.setRangeCrosshairPaint(JavaFXUtil.convertColorToAWT(crossHairColor));
  plot.setDomainCrosshairVisible(true);
  plot.setRangeCrosshairVisible(true);

  // chart properties
  chart.setBackgroundPaint(JavaFXUtil.convertColorToAWT(backgroundColor));

  // legend properties
  LegendTitle legend = chart.getLegend();
  // legend.setItemFont(legendFont);
  legend.setFrame(BlockBorder.NONE);

  // set the X axis (retention time) properties
  NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
  xAxis.setLabel("Retention time (min)");
  xAxis.setUpperMargin(0.03);
  xAxis.setLowerMargin(0.03);
  xAxis.setRangeType(RangeType.POSITIVE);
  xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 20, 20));

  // set the Y axis (intensity) properties
  NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
  yAxis.setLabel("Intensity");
  yAxis.setRangeType(RangeType.POSITIVE);
  yAxis.setAutoRangeIncludesZero(true);

  // set the fixed number formats, because otherwise JFreeChart sometimes
  // shows exponent, sometimes it doesn't
  DecimalFormat mzFormat = MZmineCore.getConfiguration().getMZFormat();
  xAxis.setNumberFormatOverride(mzFormat);
  DecimalFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat();
  yAxis.setNumberFormatOverride(intensityFormat);

  chartTitle = chartNode.getChart().getTitle();
  chartTitle.setMargin(5, 0, 0, 0);
  chartTitle.setFont(titleFont);
  chartTitle.setText("Chromatogram");

  chartNode.setCursor(Cursor.CROSSHAIR);

  // Remove the dataset if it is removed from the list
  datasets.addListener((Change<? extends ChromatogramPlotDataSet> c) -> {
    while (c.next()) {
      if (c.wasRemoved()) {
        for (ChromatogramPlotDataSet ds : c.getRemoved()) {
          int index = plot.indexOf(ds);
          plot.setDataset(index, null);
        }
      }
    }
  });

  itemLabelsVisible.addListener((prop, oldVal, newVal) -> {
    for (ChromatogramPlotDataSet dataset : datasets) {
      int datasetIndex = plot.indexOf(dataset);
      XYItemRenderer renderer = plot.getRenderer(datasetIndex);
      renderer.setBaseItemLabelsVisible(newVal);
    }
  });

  legendVisible.addListener((prop, oldVal, newVal) -> {
    legend.setVisible(newVal);
  });
}
 
Example 5
Source File: KendrickMassPlotTask.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * create 2D Kendrick mass plot
 */
private JFreeChart create2DKendrickMassPlot() {

  if (zAxisLabel.equals("none")) {
    logger.info("Creating new 2D chart instance");
    appliedSteps++;

    // load dataset
    dataset2D = new KendrickMassPlotXYDataset(parameterSet);

    // create chart
    chart = ChartFactory.createScatterPlot(title, xAxisLabel, yAxisLabel, dataset2D,
        PlotOrientation.VERTICAL, true, true, true);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainCrosshairPaint(Color.GRAY);
    plot.setRangeCrosshairPaint(Color.GRAY);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    appliedSteps++;

    // set axis
    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    NumberAxis range = (NumberAxis) plot.getRangeAxis();
    range.setRange(0, 1);
    if (xAxisLabel.contains("KMD")) {
      domain.setRange(0, 1);
    }

    // set renderer
    XYBlockPixelSizeRenderer renderer = new XYBlockPixelSizeRenderer();

    // set tooltip generator
    ScatterPlotToolTipGenerator tooltipGenerator =
        new ScatterPlotToolTipGenerator(xAxisLabel, yAxisLabel, zAxisLabel, rows);
    renderer.setSeriesToolTipGenerator(0, tooltipGenerator);
    plot.setRenderer(renderer);

    // set item label generator
    NameItemLabelGenerator generator = new NameItemLabelGenerator(rows);
    renderer.setDefaultItemLabelGenerator(generator);
    renderer.setDefaultItemLabelsVisible(false);
    renderer.setDefaultItemLabelFont(legendFont);
    renderer.setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
        TextAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -45), true);
  }
  return chart;
}
 
Example 6
Source File: VanKrevelenDiagramTask.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * create 2D Van Krevelen Diagram chart
 */
private JFreeChart create2DVanKrevelenDiagram() {
  logger.info("Creating new 2D chart instance");
  appliedSteps++;

  // load dataset
  VanKrevelenDiagramXYDataset dataset2D = new VanKrevelenDiagramXYDataset(filteredRows);

  // create chart
  chart = ChartFactory.createScatterPlot(title, "O/C", "H/C", dataset2D, PlotOrientation.VERTICAL,
      true, true, false);

  XYPlot plot = (XYPlot) chart.getPlot();
  plot.setBackgroundPaint(Color.WHITE);
  plot.setDomainCrosshairPaint(Color.GRAY);
  plot.setRangeCrosshairPaint(Color.GRAY);
  plot.setDomainCrosshairVisible(true);
  plot.setRangeCrosshairVisible(true);
  appliedSteps++;

  // set renderer
  XYBlockPixelSizeRenderer renderer = new XYBlockPixelSizeRenderer();

  // calc block sizes
  double maxX = plot.getDomainAxis().getRange().getUpperBound();
  double maxY = plot.getRangeAxis().getRange().getUpperBound();

  renderer.setBlockWidth(0.001);
  renderer.setBlockHeight(renderer.getBlockWidth() / (maxX / maxY));

  // set tooltip generator
  ScatterPlotToolTipGenerator tooltipGenerator =
      new ScatterPlotToolTipGenerator("O/C", "H/C", zAxisLabel, filteredRows);
  renderer.setSeriesToolTipGenerator(0, tooltipGenerator);
  plot.setRenderer(renderer);

  // set item label generator
  NameItemLabelGenerator generator = new NameItemLabelGenerator(filteredRows);
  renderer.setDefaultItemLabelGenerator(generator);
  renderer.setDefaultItemLabelsVisible(false);
  renderer.setDefaultItemLabelFont(legendFont);
  renderer.setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
      TextAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -45), true);

  return chart;
}
 
Example 7
Source File: ChartJFreeChartOutputScatter.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void initChart(final IScope scope, final String chartname) {
	super.initChart(scope, chartname);

	final XYPlot pp = (XYPlot) chart.getPlot();
	pp.setDomainGridlinePaint(axesColor);
	pp.setRangeGridlinePaint(axesColor);
	pp.setDomainCrosshairPaint(axesColor);
	pp.setRangeCrosshairPaint(axesColor);
	pp.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
	pp.setDomainCrosshairVisible(false);
	pp.setRangeCrosshairVisible(false);

	pp.getDomainAxis().setAxisLinePaint(axesColor);
	pp.getDomainAxis().setTickLabelFont(getTickFont());
	pp.getDomainAxis().setLabelFont(getLabelFont());
	if (textColor != null) {
		pp.getDomainAxis().setLabelPaint(textColor);
		pp.getDomainAxis().setTickLabelPaint(textColor);
	}

	NumberAxis axis = (NumberAxis) pp.getRangeAxis();
	axis = formatYAxis(scope, axis);
	pp.setRangeAxis(axis);
	if (ytickunit > 0) {
		((NumberAxis) pp.getRangeAxis()).setTickUnit(new NumberTickUnit(ytickunit));
		pp.setRangeGridlinesVisible(true);
	} else {
		pp.setRangeGridlinesVisible(GamaPreferences.Displays.CHART_GRIDLINES.getValue());
	}

	// resetAutorange(scope);

	if (getType() == ChartOutput.SERIES_CHART) {
		if (xlabel == null) {
			xlabel = "time";
		}
	}
	if (getType() == ChartOutput.XY_CHART) {}
	if (getType() == ChartOutput.SCATTER_CHART) {}
	if (!this.getXTickValueVisible(scope)) {
		pp.getDomainAxis().setTickMarksVisible(false);
		pp.getDomainAxis().setTickLabelsVisible(false);

	}

}
 
Example 8
Source File: ChartJFreeChartOutputHeatmap.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void initChart(final IScope scope, final String chartname) {
	super.initChart(scope, chartname);

	final XYPlot pp = (XYPlot) chart.getPlot();
	pp.setDomainGridlinePaint(axesColor);
	pp.setRangeGridlinePaint(axesColor);
	pp.setDomainCrosshairPaint(axesColor);
	pp.setRangeCrosshairPaint(axesColor);
	pp.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
	pp.setDomainCrosshairVisible(false);
	pp.setRangeCrosshairVisible(false);
	pp.setRangeGridlinesVisible(false);
	pp.setDomainGridlinesVisible(false);

	pp.getDomainAxis().setAxisLinePaint(axesColor);

	pp.getDomainAxis().setTickLabelFont(getTickFont());
	pp.getDomainAxis().setLabelFont(getLabelFont());
	if (textColor != null) {
		pp.getDomainAxis().setLabelPaint(textColor);
		pp.getDomainAxis().setTickLabelPaint(textColor);
	}
	if (xtickunit > 0) {
		((NumberAxis) pp.getDomainAxis()).setTickUnit(new NumberTickUnit(xtickunit));
	}

	pp.getRangeAxis().setAxisLinePaint(axesColor);
	pp.getRangeAxis().setLabelFont(getLabelFont());
	pp.getRangeAxis().setTickLabelFont(getTickFont());
	if (textColor != null) {
		pp.getRangeAxis().setLabelPaint(textColor);
		pp.getRangeAxis().setTickLabelPaint(textColor);
	}
	if (ytickunit > 0) {
		((NumberAxis) pp.getRangeAxis()).setTickUnit(new NumberTickUnit(ytickunit));
	}

	// resetAutorange(scope);

	if (xlabel != null && !xlabel.isEmpty()) {
		pp.getDomainAxis().setLabel(xlabel);
	}
	if (ylabel != null && !ylabel.isEmpty()) {
		pp.getRangeAxis().setLabel(ylabel);
	}

}