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

The following examples show how to use org.jfree.chart.plot.XYPlot#setDatasetRenderingOrder() . 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: SpectrumChartFactory.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public static JFreeChart createChart(PseudoSpectrumDataSet dataset, boolean showTitle,
    boolean showLegend, double rt, double precursorMZ) {
  //
  if (dataset == null)
    return null;
  //
  NumberFormat mzForm = MZmineCore.getConfiguration().getMZFormat();
  NumberFormat rtForm = MZmineCore.getConfiguration().getRTFormat();
  NumberFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat();

  String title = "";
  if (precursorMZ == 0)
    title = "RT=" + mzForm.format(precursorMZ);
  else
    title = MessageFormat.format("MSMS for m/z={0} RT={1}", mzForm.format(precursorMZ),
        rtForm.format(rt));

  JFreeChart chart = ChartFactory.createXYLineChart(title, // title
      "m/z", // x-axis label
      "Intensity", // y-axis label
      dataset, // data set
      PlotOrientation.VERTICAL, // orientation
      true, // isotopeFlag, // create legend?
      true, // generate tooltips?
      false // generate URLs?
  );
  chart.setBackgroundPaint(Color.white);
  chart.getTitle().setVisible(false);
  // set the plot properties
  XYPlot plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setAxisOffset(RectangleInsets.ZERO_INSETS);

  // set rendering order
  plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

  // set crosshair (selection) properties
  plot.setDomainCrosshairVisible(false);
  plot.setRangeCrosshairVisible(false);

  // set the X axis (retention time) properties
  NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
  xAxis.setNumberFormatOverride(mzForm);
  xAxis.setUpperMargin(0.08);
  xAxis.setLowerMargin(0.00);
  xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 20, 20));
  xAxis.setAutoRangeIncludesZero(true);
  xAxis.setMinorTickCount(5);

  // set the Y axis (intensity) properties
  NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
  yAxis.setNumberFormatOverride(intensityFormat);
  yAxis.setUpperMargin(0.20);

  PseudoSpectraRenderer renderer = new PseudoSpectraRenderer(Color.BLACK, false);
  plot.setRenderer(0, renderer);
  plot.setRenderer(1, renderer);
  plot.setRenderer(2, renderer);
  renderer.setSeriesVisibleInLegend(1, false);
  renderer.setSeriesPaint(2, Color.ORANGE);
  //
  chart.getTitle().setVisible(showTitle);
  chart.getLegend().setVisible(showLegend);
  //
  if (precursorMZ != 0)
    addPrecursorMarker(chart, precursorMZ);
  return chart;
}
 
Example 2
Source File: PseudoSpectrum.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public static JFreeChart createChart(PseudoSpectrumDataSet dataset, RawDataFile raw, boolean sum,
    String title) {
  //
  JFreeChart chart = ChartFactory.createXYLineChart(title, // title
      "m/z", // x-axis label
      "Intensity", // y-axis label
      dataset, // data set
      PlotOrientation.VERTICAL, // orientation
      true, // isotopeFlag, // create legend?
      true, // generate tooltips?
      false // generate URLs?
  );
  chart.setBackgroundPaint(Color.white);
  chart.getTitle().setVisible(false);
  // set the plot properties
  XYPlot plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setAxisOffset(RectangleInsets.ZERO_INSETS);

  // set rendering order
  plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

  // set crosshair (selection) properties
  plot.setDomainCrosshairVisible(false);
  plot.setRangeCrosshairVisible(false);

  NumberFormat mzFormat = MZmineCore.getConfiguration().getMZFormat();
  NumberFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat();

  // set the X axis (retention time) properties
  NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
  xAxis.setNumberFormatOverride(mzFormat);
  xAxis.setUpperMargin(0.08);
  xAxis.setLowerMargin(0.00);
  xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 20, 20));
  xAxis.setAutoRangeIncludesZero(true);
  xAxis.setMinorTickCount(5);

  // set the Y axis (intensity) properties
  NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
  yAxis.setNumberFormatOverride(intensityFormat);
  yAxis.setUpperMargin(0.20);

  PseudoSpectraRenderer renderer = new PseudoSpectraRenderer(Color.BLACK, false);
  plot.setRenderer(0, renderer);
  plot.setRenderer(1, renderer);
  plot.setRenderer(2, renderer);
  renderer.setSeriesVisibleInLegend(1, false);
  renderer.setSeriesPaint(2, Color.ORANGE);
  //
  return chart;
}
 
Example 3
Source File: Chart.java    From freeacs with MIT License 4 votes vote down vote up
/**
 * All params can be null.
 *
 * @param min - the minimum number on the left range axis (must be set if max is set)
 * @param max - the maximum number on the left range axis (must be set if min is set)
 * @param method2 - the method to run out of Record, and populates a bar series (right range axis)
 * @param highLightIndex - the index to highlight
 * @return
 * @throws Exception
 */
public JFreeChart makeTimeChart(Double min, Double max, String method2, Integer highLightIndex)
    throws Exception {
  startTms = System.currentTimeMillis();
  endTms = 0;
  XYBarRenderer.setDefaultShadowsVisible(false);
  TimeSeriesCollection data = new TimeSeriesCollection();
  Map<String, TimeSeries> timeSeriesMap = makeTimeSeriesMap(method, recordMap, keyNames);
  for (TimeSeries timeSeries : timeSeriesMap.values()) {
    data.addSeries(timeSeries);
  }
  String yAxisLabel = method;
  String denominator = Record.getDenominator(report.getRecordClass(), method.toLowerCase());
  if (denominator != null) {
    yAxisLabel += " (" + denominator + ")";
  }
  chart = ChartFactory.createTimeSeriesChart(title, "Time", yAxisLabel, data, true, true, true);
  XYPlot plot = (XYPlot) chart.getPlot();
  if (method2 != null) {
    Map<Key, R> recordMap2 = recordMap;
    TimeSeriesCollection data2 = new TimeSeriesCollection();
    if (keyNames.length > 0) {
      recordMap2 = report.getMapAggregatedOn();
    }
    Map<String, TimeSeries> timeSeriesMap2 = makeTimeSeriesMap(method2, recordMap2);
    if (timeSeriesMap2.get("Total (" + method2 + ")") != null) {
      data2.addSeries(timeSeriesMap2.get("Total (" + method2 + ")"));
    }
    String y2AxisLabel = method2;
    String demoninator2 = Record.getDenominator(report.getRecordClass(), method2.toLowerCase());
    if (demoninator2 != null) {
      y2AxisLabel += " (" + demoninator2 + ")";
    }
    NumberAxis axis2 = new NumberAxis(y2AxisLabel);
    XYBarRenderer renderer2 = new XYBarRenderer(0.20);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    plot.setDataset(1, data2);
    plot.setRenderer(1, renderer2);
    plot.mapDatasetToRangeAxis(1, 1);
    renderer2.setBarPainter(new StandardXYBarPainter());
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
  }
  if (min != null && max != null) {
    plot.getRangeAxis(0).setRange(min, max);
  }

  if (highLightIndex != null) {
    chart.getXYPlot().getRenderer().setSeriesStroke(highLightIndex, new BasicStroke(5f));
  }

  XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
  renderer.setDefaultShapesVisible(true);
  renderer.setUseFillPaint(true);
  renderer.setDefaultFillPaint(Color.white);

  long diff = endTms - startTms;
  String format;
  if (diff > NINTY_DAYS) {
    format = "MMM-yyyy";
  } else if (diff > TWO_DAYS) {
    format = "dd-MMM";
  } else if (diff > TWO_MINUTES) {
    format = "HH:mm";
  } else {
    format = "HH:mm:ss";
  }
  DateAxis axis = (DateAxis) plot.getDomainAxis();
  axis.setDateFormatOverride(new SimpleDateFormat(format));

  LegendTitle lt = chart.getLegend(0);
  lt.setPosition(RectangleEdge.RIGHT);

  if (displayFrame) {
    ChartFrame frame = new ChartFrame(title, chart);
    frame.pack();
    frame.setVisible(true);
  }

  return chart;
}
 
Example 4
Source File: PlotUtil.java    From dl4j-tutorials with MIT License 4 votes vote down vote up
private static JFreeChart createChart(XYZDataset dataset, double[] mins, double[] maxs, int nPoints, XYDataset xyData) {
    NumberAxis xAxis = new NumberAxis("X");
    xAxis.setRange(mins[0],maxs[0]);


    NumberAxis yAxis = new NumberAxis("Y");
    yAxis.setRange(mins[1], maxs[1]);

    XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setBlockWidth((maxs[0]-mins[0])/(nPoints-1));
    renderer.setBlockHeight((maxs[1] - mins[1]) / (nPoints - 1));
    PaintScale scale = new GrayPaintScale(0, 1.0);
    renderer.setPaintScale(scale);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    JFreeChart chart = new JFreeChart("", plot);
    chart.getXYPlot().getRenderer().setSeriesVisibleInLegend(0, false);


    NumberAxis scaleAxis = new NumberAxis("Probability (class 0)");
    scaleAxis.setAxisLinePaint(Color.white);
    scaleAxis.setTickMarkPaint(Color.white);
    scaleAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 7));
    PaintScaleLegend legend = new PaintScaleLegend(new GrayPaintScale(),
            scaleAxis);
    legend.setStripOutlineVisible(false);
    legend.setSubdivisionCount(20);
    legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    legend.setAxisOffset(5.0);
    legend.setMargin(new RectangleInsets(5, 5, 5, 5));
    legend.setFrame(new BlockBorder(Color.red));
    legend.setPadding(new RectangleInsets(10, 10, 10, 10));
    legend.setStripWidth(10);
    legend.setPosition(RectangleEdge.LEFT);
    chart.addSubtitle(legend);

    ChartUtilities.applyCurrentTheme(chart);

    plot.setDataset(1, xyData);
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    renderer2.setBaseLinesVisible(false);
    plot.setRenderer(1, renderer2);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    return chart;
}
 
Example 5
Source File: FrmElevationFilter.java    From Course_Generator with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Update the chart
 * 
 * @param dataset1
 * @param dataset2
 * @return
 */
private JFreeChart CreateChart(XYDataset dataset1, XYDataset dataset2) {
	JFreeChart chart = ChartFactory.createXYAreaChart("",
			// x axis label
			bundle.getString("frmElevationFilter.labelX"), // "Distance"
			// y axis label
			bundle.getString("frmElevationFilter.labelY1"), // "Elevation"
			dataset1, // data
			PlotOrientation.VERTICAL, false, // include legend
			true, // tooltips
			false // urls
	);

	// -- Background color
	chart.setBackgroundPaint(Color.white);
	chart.setAntiAlias(true);

	XYPlot plot = (XYPlot) chart.getPlot();
	plot.setBackgroundPaint(Color.white);
	plot.setDomainGridlinePaint(Color.gray);
	plot.setRangeGridlinePaint(Color.gray);
	plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

	XYAreaRenderer renderer = new XYAreaRenderer();
	renderer.setSeriesPaint(0, new Color(0x99, 0xff, 0x00));
	renderer.setOutline(true);
	renderer.setSeriesOutlineStroke(0, new BasicStroke(2.0f));
	plot.setRenderer(0, renderer);

	NumberAxis rangeAxis2 = new NumberAxis("");// bundle.getString("JPanelAnalysisTimeDist.labelY2")); // "Time"
	// plot.setRangeAxis(1, rangeAxis2);
	plot.setDataset(1, dataset2);
	plot.setRangeAxis(1, rangeAxis2);
	// plot.mapDatasetToRangeAxis(1, 1);
	StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
	renderer2.setSeriesPaint(0, Color.red);
	renderer2.setSeriesStroke(0, new BasicStroke(1.0f));
	plot.setRenderer(1, renderer2);

	// -- Select the display order
	plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

	return chart;
}
 
Example 6
Source File: JPanelAnalysisSpeed.java    From Course_Generator with GNU General Public License v3.0 4 votes vote down vote up
private JFreeChart CreateChart(XYDataset dataset1, XYDataset dataset2) {
	JFreeChart chart = ChartFactory.createXYAreaChart("",
			// x axis label
			bundle.getString("JPanelAnalysisSpeed.labelX"), // "Distance",
			// y axis label
			bundle.getString("JPanelAnalysisSpeed.labelY"), // "Speed"
			dataset1, // data
			PlotOrientation.VERTICAL, false, // include legend
			true, // tooltips
			false // urls
	);

	chart.setBackgroundPaint(Color.white); // Panel background color
	chart.setAntiAlias(true);

	XYPlot plot = chart.getXYPlot();
	plot.setBackgroundPaint(Color.white);
	plot.setDomainGridlinePaint(Color.gray);
	plot.setRangeGridlinePaint(Color.gray);
	plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

	XYAreaRenderer renderer = new XYAreaRenderer();
	renderer.setSeriesPaint(0, new Color(0x99, 0xff, 0x00));
	renderer.setOutline(true);
	renderer.setSeriesOutlineStroke(0, new BasicStroke(2.0f));
	plot.setRenderer(0, renderer);

	NumberAxis rangeAxis2 = new NumberAxis();
	plot.setRangeAxis(1, rangeAxis2);
	plot.setDataset(1, dataset2);
	plot.setRangeAxis(1, rangeAxis2);
	plot.mapDatasetToRangeAxis(1, 1);

	StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
	renderer2.setSeriesPaint(0, Color.red);
	plot.setRenderer(1, renderer2);

	// -- Select the display order
	plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

	return chart;
}
 
Example 7
Source File: JPanelAnalysisSpeedSlope.java    From Course_Generator with GNU General Public License v3.0 4 votes vote down vote up
private JFreeChart CreateChart(XYDataset dataset1, XYDataset dataset2) {
	JFreeChart chart = ChartFactory.createScatterPlot("",
			// x axis label
			bundle.getString("JPanelAnalysisSpeedSlope.labelX"), // "Slope",
			// y axis label
			bundle.getString("JPanelAnalysisSpeedSlope.labelY"), // "Speed",
			// data
			dataset1, PlotOrientation.VERTICAL, false, // include legend
			true, // tooltips
			false // urls
	);

	chart.setBackgroundPaint(Color.white); // Panel background color
	chart.setAntiAlias(true);

	XYPlot plot = chart.getXYPlot();
	plot.setBackgroundPaint(Color.white);
	plot.setDomainGridlinePaint(Color.gray);
	plot.setRangeGridlinePaint(Color.gray);
	plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
	plot.setRangeCrosshairLockedOnData(false);

	XYDotRenderer renderer = new XYDotRenderer();
	renderer.setSeriesPaint(0, new Color(0x6B, 0xB2, 0x00));
	renderer.setDotWidth(2);
	renderer.setDotHeight(2);
	plot.setRenderer(renderer);

	NumberAxis rangeAxis2 = new NumberAxis();
	plot.setRangeAxis(1, rangeAxis2);
	plot.setDataset(1, dataset2);
	plot.setRangeAxis(1, rangeAxis2);
	plot.mapDatasetToRangeAxis(1, 1);

	XYAreaRenderer renderer2 = new XYAreaRenderer();
	renderer2.setSeriesPaint(0, new Color(0x99, 0xff, 0x00, 0x80));
	renderer2.setOutline(true);
	renderer2.setSeriesOutlinePaint(0, new Color(0x80, 0x80, 0x80, 0x80));
	renderer2.setSeriesOutlineStroke(0, new BasicStroke(2.0f));
	plot.setRenderer(1, renderer2);

	/*
	 * StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
	 * renderer2.setSeriesPaint(0, Color.red); plot.setRenderer(1, renderer2);
	 */

	// -- Select the display order
	plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);

	return chart;
}
 
Example 8
Source File: JPanelAnalysisTimeDist.java    From Course_Generator with GNU General Public License v3.0 4 votes vote down vote up
private JFreeChart CreateChart(XYDataset dataset1, XYDataset dataset2) {
	JFreeChart chart = ChartFactory.createXYAreaChart("",
			// x axis label
			bundle.getString("JPanelAnalysisTimeDist.labelX"), // "Distance"
			// y axis label
			bundle.getString("JPanelAnalysisTimeDist.labelY1"), // "Elevation"
			dataset1, // data
			PlotOrientation.VERTICAL, false, // include legend
			true, // tooltips
			false // urls
	);

	// -- Background color
	chart.setBackgroundPaint(Color.white);
	chart.setAntiAlias(true);

	XYPlot plot = (XYPlot) chart.getPlot();
	plot.setBackgroundPaint(Color.white);
	plot.setDomainGridlinePaint(Color.gray);
	plot.setRangeGridlinePaint(Color.gray);
	plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

	XYAreaRenderer renderer = new XYAreaRenderer();
	renderer.setSeriesPaint(0, new Color(0x99, 0xff, 0x00));
	renderer.setOutline(true);
	renderer.setSeriesOutlineStroke(0, new BasicStroke(2.0f));
	plot.setRenderer(0, renderer);

	NumberAxis rangeAxis2 = new NumberAxis(bundle.getString("JPanelAnalysisTimeDist.labelY2")); // "Time"
	plot.setRangeAxis(1, rangeAxis2);
	plot.setDataset(1, dataset2);
	plot.setRangeAxis(1, rangeAxis2);
	plot.mapDatasetToRangeAxis(1, 1);
	StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
	renderer2.setSeriesPaint(0, Color.red);
	plot.setRenderer(1, renderer2);

	// -- Select the display order
	plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

	return chart;
}
 
Example 9
Source File: JPanelAnalysisTimeTemperature.java    From Course_Generator with GNU General Public License v3.0 4 votes vote down vote up
private JFreeChart CreateChart(XYDataset dataset1, XYDataset dataset2) {
	JFreeChart chart = ChartFactory.createXYLineChart("",
			// x axis label
			bundle.getString("JPanelAnalysisTimeDist.labelX"), // "Distance"
			// y axis label
			bundle.getString("JPanelAnalysisTimeDist.labelY1"), // "Elevation"
			dataset1, // data
			PlotOrientation.VERTICAL, false, // include legend
			true, // tooltips
			false // urls
	);

	// -- Background color
	chart.setBackgroundPaint(Color.white);
	chart.setAntiAlias(true);

	XYPlot plot = (XYPlot) chart.getPlot();
	plot.setBackgroundPaint(Color.white);
	plot.setDomainGridlinePaint(Color.gray);
	plot.setRangeGridlinePaint(Color.gray);
	plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

	XYAreaRenderer renderer = new XYAreaRenderer();
	renderer.setSeriesPaint(0, new Color(0x99, 0xff, 0x00));
	renderer.setOutline(true);
	renderer.setSeriesOutlineStroke(0, new BasicStroke(2.0f));
	plot.setRenderer(0, renderer);

	NumberAxis rangeAxis2 = new NumberAxis(bundle.getString("JPanelAnalysisTimeTemperature.labelY2")); // "Time"
	plot.setRangeAxis(1, rangeAxis2);
	plot.setDataset(1, dataset2);
	plot.setRangeAxis(1, rangeAxis2);
	plot.mapDatasetToRangeAxis(1, 1);
	StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
	renderer2.setSeriesPaint(0, Color.red);
	plot.setRenderer(1, renderer2);

	// -- Select the display order
	plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

	return chart;
}
 
Example 10
Source File: MsSpectrumPlotWindowController.java    From old-mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
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.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);

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

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

    // set the X axis (m/z) properties
    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setLabel("m/z");
    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);

    chartNode.setCursor(Cursor.CROSSHAIR);

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

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

    legendVisible.addListener((prop, oldVal, newVal) -> {
      legend.setVisible(newVal);
    });

  }
 
Example 11
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 12
Source File: SpectrumChartFactory.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
public static JFreeChart createChart(PseudoSpectrumDataSet dataset, boolean showTitle,
    boolean showLegend, double rt, double precursorMZ) {
  //
  if (dataset == null)
    return null;
  //
  NumberFormat mzForm = MZmineCore.getConfiguration().getMZFormat();
  NumberFormat rtForm = MZmineCore.getConfiguration().getRTFormat();
  NumberFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat();

  String title = "";
  if (precursorMZ == 0)
    title = "RT=" + mzForm.format(precursorMZ);
  else
    title = MessageFormat.format("MSMS for m/z={0} RT={1}", mzForm.format(precursorMZ),
        rtForm.format(rt));

  JFreeChart chart = ChartFactory.createXYLineChart(title, // title
      "m/z", // x-axis label
      "Intensity", // y-axis label
      dataset, // data set
      PlotOrientation.VERTICAL, // orientation
      true, // isotopeFlag, // create legend?
      true, // generate tooltips?
      false // generate URLs?
  );
  chart.setBackgroundPaint(Color.white);
  chart.getTitle().setVisible(false);
  // set the plot properties
  XYPlot plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setAxisOffset(RectangleInsets.ZERO_INSETS);

  // set rendering order
  plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

  // set crosshair (selection) properties
  plot.setDomainCrosshairVisible(false);
  plot.setRangeCrosshairVisible(false);

  // set the X axis (retention time) properties
  NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
  xAxis.setNumberFormatOverride(mzForm);
  xAxis.setUpperMargin(0.08);
  xAxis.setLowerMargin(0.00);
  xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 20, 20));
  xAxis.setAutoRangeIncludesZero(true);
  xAxis.setMinorTickCount(5);

  // set the Y axis (intensity) properties
  NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
  yAxis.setNumberFormatOverride(intensityFormat);
  yAxis.setUpperMargin(0.20);

  PseudoSpectraRenderer renderer = new PseudoSpectraRenderer(Color.BLACK, false);
  plot.setRenderer(0, renderer);
  plot.setRenderer(1, renderer);
  plot.setRenderer(2, renderer);
  renderer.setSeriesVisibleInLegend(1, false);
  renderer.setSeriesPaint(2, Color.ORANGE);
  //
  chart.getTitle().setVisible(showTitle);
  chart.getLegend().setVisible(showLegend);
  //
  if (precursorMZ != 0)
    addPrecursorMarker(chart, precursorMZ);
  return chart;
}
 
Example 13
Source File: PseudoSpectrum.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
public static JFreeChart createChart(PseudoSpectrumDataSet dataset, RawDataFile raw, boolean sum,
    String title) {
  //
  JFreeChart chart = ChartFactory.createXYLineChart(title, // title
      "m/z", // x-axis label
      "Intensity", // y-axis label
      dataset, // data set
      PlotOrientation.VERTICAL, // orientation
      true, // isotopeFlag, // create legend?
      true, // generate tooltips?
      false // generate URLs?
  );
  chart.setBackgroundPaint(Color.white);
  chart.getTitle().setVisible(false);
  // set the plot properties
  XYPlot plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setAxisOffset(RectangleInsets.ZERO_INSETS);

  // set rendering order
  plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

  // set crosshair (selection) properties
  plot.setDomainCrosshairVisible(false);
  plot.setRangeCrosshairVisible(false);

  NumberFormat mzFormat = MZmineCore.getConfiguration().getMZFormat();
  NumberFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat();

  // set the X axis (retention time) properties
  NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
  xAxis.setNumberFormatOverride(mzFormat);
  xAxis.setUpperMargin(0.08);
  xAxis.setLowerMargin(0.00);
  xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 20, 20));
  xAxis.setAutoRangeIncludesZero(true);
  xAxis.setMinorTickCount(5);

  // set the Y axis (intensity) properties
  NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
  yAxis.setNumberFormatOverride(intensityFormat);
  yAxis.setUpperMargin(0.20);

  PseudoSpectraRenderer renderer = new PseudoSpectraRenderer(Color.BLACK, false);
  plot.setRenderer(0, renderer);
  plot.setRenderer(1, renderer);
  plot.setRenderer(2, renderer);
  renderer.setSeriesVisibleInLegend(1, false);
  renderer.setSeriesPaint(2, Color.ORANGE);
  //
  return chart;
}
 
Example 14
Source File: CandlestickChart.java    From ta4j-origins with MIT License 4 votes vote down vote up
public static void main(String[] args) {
    /**
     * Getting time series
     */
    TimeSeries series = CsvTradesLoader.loadBitstampSeries();
    
    /**
     * Creating the OHLC dataset
     */
    OHLCDataset ohlcDataset = createOHLCDataset(series);
    
    /**
     * Creating the additional dataset
     */
    TimeSeriesCollection xyDataset = createAdditionalDataset(series);
    
    /**
     * Creating the chart
     */
    JFreeChart chart = ChartFactory.createCandlestickChart(
            "Bitstamp BTC price",
            "Time",
            "USD",
            ohlcDataset,
            true);
    // Candlestick rendering
    CandlestickRenderer renderer = new CandlestickRenderer();
    renderer.setAutoWidthMethod(CandlestickRenderer.WIDTHMETHOD_SMALLEST);
    XYPlot plot = chart.getXYPlot();
    plot.setRenderer(renderer);
    // Additional dataset
    int index = 1;
    plot.setDataset(index, xyDataset);
    plot.mapDatasetToRangeAxis(index, 0);
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false);
    renderer2.setSeriesPaint(index, Color.blue);
    plot.setRenderer(index, renderer2);
    // Misc
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setBackgroundPaint(Color.white);
    NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
    numberAxis.setAutoRangeIncludesZero(false);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    
    /**
     * Displaying the chart
     */
    displayChart(chart);
}