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

The following examples show how to use org.jfree.chart.plot.XYPlot#addDomainMarker() . 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: Chart.java    From crypto-bot with Apache License 2.0 6 votes vote down vote up
private static void addBuySellSignals(TimeSeries series, Strategy strategy, XYPlot plot) {
	// Running the strategy
	TimeSeriesManager seriesManager = new TimeSeriesManager(series);
	List<Trade> trades = seriesManager.run(strategy).getTrades();
	// Adding markers to plot
	for (Trade trade : trades) {
		// Buy signal
		double buySignalTickTime = new Minute(
				Date.from(series.getBar(trade.getEntry().getIndex()).getEndTime().toInstant()))
						.getFirstMillisecond();
		Marker buyMarker = new ValueMarker(buySignalTickTime);
		buyMarker.setPaint(Color.GREEN);
		buyMarker.setLabel("B");
		plot.addDomainMarker(buyMarker);
		// Sell signal
		double sellSignalTickTime = new Minute(
				Date.from(series.getBar(trade.getExit().getIndex()).getEndTime().toInstant()))
						.getFirstMillisecond();
		Marker sellMarker = new ValueMarker(sellSignalTickTime);
		sellMarker.setPaint(Color.RED);
		sellMarker.setLabel("S");
		plot.addDomainMarker(sellMarker);
	}
}
 
Example 2
Source File: ChartUtil.java    From ezScrum with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unused")
private void setMarker(XYPlot plot) {
	Iterator<Date> ir = m_dateMarkerMap.keySet().iterator();
	int index = 1;
	while (ir.hasNext()) {

		Date key = ir.next();

		final Marker marker = new IntervalMarker(key.getTime(),
				m_dateMarkerMap.get(key).getTime());

		if (this.m_visualMarkerLabel)
			marker.setLabel("#" + index);
		// marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
		// marker.setLabelTextAnchor(TextAnchor.TOP_LEFT);

		marker.setAlpha(0.3f);
		//marker.setPaint(this.m_markerColor);

		plot.addDomainMarker(marker);
		index++;
	}
}
 
Example 3
Source File: MarkerTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks that an XYPlot deregisters listeners when clearing markers.
 */
public void testListenersWithXYPlot() {
    XYPlot plot = new XYPlot();
    ValueMarker marker1 = new ValueMarker(1.0);
    ValueMarker marker2 = new ValueMarker(2.0);
    plot.addDomainMarker(marker1);
    plot.addRangeMarker(marker2);
    EventListener[] listeners1 = marker1.getListeners(
            MarkerChangeListener.class);
    assertTrue(Arrays.asList(listeners1).contains(plot));
    EventListener[] listeners2 = marker1.getListeners(
            MarkerChangeListener.class);
    assertTrue(Arrays.asList(listeners2).contains(plot));
    plot.clearDomainMarkers();
    plot.clearRangeMarkers();
    listeners1 = marker1.getListeners(MarkerChangeListener.class);
    assertFalse(Arrays.asList(listeners1).contains(plot));
    listeners2 = marker1.getListeners(MarkerChangeListener.class);
    assertFalse(Arrays.asList(listeners2).contains(plot));
}
 
Example 4
Source File: MarkerTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks that an XYPlot deregisters listeners when clearing markers.
 */
public void testListenersWithXYPlot() {
    XYPlot plot = new XYPlot();
    ValueMarker marker1 = new ValueMarker(1.0);
    ValueMarker marker2 = new ValueMarker(2.0);
    plot.addDomainMarker(marker1);
    plot.addRangeMarker(marker2);
    EventListener[] listeners1 = marker1.getListeners(
            MarkerChangeListener.class);
    assertTrue(Arrays.asList(listeners1).contains(plot));
    EventListener[] listeners2 = marker1.getListeners(
            MarkerChangeListener.class);
    assertTrue(Arrays.asList(listeners2).contains(plot));
    plot.clearDomainMarkers();
    plot.clearRangeMarkers();
    listeners1 = marker1.getListeners(MarkerChangeListener.class);
    assertFalse(Arrays.asList(listeners1).contains(plot));
    listeners2 = marker1.getListeners(MarkerChangeListener.class);
    assertFalse(Arrays.asList(listeners2).contains(plot));
}
 
Example 5
Source File: GrammarvizChartPanel.java    From grammarviz2_src with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param plot plot for the marker
 * @param startVal start postion
 * @param endVal end position
 */
protected void addMarker(XYPlot plot, int startVal, int endVal) {
  IntervalMarker marker = new IntervalMarker(startVal, endVal);
  marker.setLabelOffsetType(LengthAdjustmentType.EXPAND);
  marker.setPaint(new Color(134, 254, 225));
  marker.setAlpha((float) 0.60);
  marker.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
  marker.setLabelPaint(Color.green);
  marker.setLabelAnchor(RectangleAnchor.TOP_LEFT);
  marker.setLabelTextAnchor(TextAnchor.TOP_LEFT);

  plot.addDomainMarker(marker, Layer.BACKGROUND);

  ValueMarker markStart = new ValueMarker(startVal, new Color(31, 254, 225),
      new BasicStroke(2.0f));
  ValueMarker markEnd = new ValueMarker(endVal, new Color(31, 254, 225), new BasicStroke(2.0f));
  plot.addDomainMarker(markStart, Layer.BACKGROUND);
  plot.addDomainMarker(markEnd, Layer.BACKGROUND);
}
 
Example 6
Source File: LineChartPanel.java    From nmonvisualizer with Apache License 2.0 6 votes vote down vote up
@Override
public void addMarkers(List<Marker> markers) {
    if (getChart() != null) {
        XYPlot plot = getChart().getXYPlot();

        plot.clearDomainMarkers();
        plot.clearRangeMarkers();

        for (Marker marker : markers) {
            if (marker instanceof RangeValueMarker) {
                plot.addRangeMarker(marker);
            }
            else if (marker instanceof DomainValueMarker) {
                plot.addDomainMarker(marker);
            }

            firePropertyChange("annotation", null, marker);
        }
    }
}
 
Example 7
Source File: GrammarvizChartPanel.java    From grammarviz2_src with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Adds an anomaly marker.
 * 
 * @param plot plot for the marker
 * @param startVal start postion
 * @param endVal end position
 */
protected void addAnomalyMarker(XYPlot plot, int startVal, int endVal) {

  IntervalMarker marker = new IntervalMarker(startVal, endVal);

  marker.setLabelOffsetType(LengthAdjustmentType.EXPAND);
  marker.setPaint(new Color(134, 254, 225));
  marker.setAlpha((float) 0.60);
  marker.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
  marker.setLabelPaint(Color.pink);
  marker.setLabelAnchor(RectangleAnchor.TOP_LEFT);
  marker.setLabelTextAnchor(TextAnchor.TOP_LEFT);

  marker.setPaint(Color.pink);

  plot.addDomainMarker(marker, Layer.BACKGROUND);
}
 
Example 8
Source File: HistogramChartFactory.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds annotations to the Gaussian fit parameters
 * 
 * @param plot
 * @param fit Gaussian fit {normalisation factor, mean, sigma}
 */
public static void addGaussianFitAnnotations(XYPlot plot, double[] fit) {
  Paint c = plot.getDomainCrosshairPaint();
  BasicStroke s = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1,
      new float[] {5f, 2.5f}, 0);

  plot.addDomainMarker(new ValueMarker(fit[1], c, s));
  plot.addDomainMarker(new ValueMarker(fit[1] - fit[2], c, s));
  plot.addDomainMarker(new ValueMarker(fit[1] + fit[2], c, s));
}
 
Example 9
Source File: KafkaFT.java    From flink-perf with Apache License 2.0 5 votes vote down vote up
private static void addIllegalEvent(XYPlot xyplot, long pos) {
	ValueMarker vm = new ValueMarker(pos);
	vm.setPaint(ChartColor.LIGHT_YELLOW);
	vm.setLabelOffset(new RectangleInsets(10.0D, 1.0D, 1.0D, 1.0D));
	vm.setLabel("Illegal State");
	vm.setStroke(new BasicStroke(2));
	xyplot.addDomainMarker(vm);
}
 
Example 10
Source File: KafkaFT.java    From flink-perf with Apache License 2.0 5 votes vote down vote up
private static void addKillEvent(XYPlot xyplot, long pos) {
	ValueMarker vm = new ValueMarker(pos);
	vm.setPaint(ChartColor.VERY_DARK_GREEN);
	vm.setLabelOffset(new RectangleInsets(10.0D, 1.0D, 1.0D, 1.0D));
	vm.setLabel("Container Kill Event");
	vm.setStroke(new BasicStroke(2));
	xyplot.addDomainMarker(vm);
}
 
Example 11
Source File: Scatter.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public void addAnnotation( String text, double x ) {
    XYPlot plot = (XYPlot) getChart().getPlot();
    Color color = new Color(0, 0, 0, 100);
    Marker updateMarker = new ValueMarker(x, color, new BasicStroke(2f));
    plot.addDomainMarker(updateMarker);
    if (text != null) {
        XYTextAnnotation updateLabel = new XYTextAnnotation(text, x, 0);
        updateLabel.setRotationAnchor(TextAnchor.BASELINE_CENTER);
        updateLabel.setTextAnchor(TextAnchor.BASELINE_CENTER);
        updateLabel.setRotationAngle(-3.14 / 2);
        updateLabel.setPaint(Color.black);
        plot.addAnnotation(updateLabel);
    }
    setShapeLinesVisibility(plot);
}
 
Example 12
Source File: HouseholdsPanel.java    From computational-economy with GNU General Public License v3.0 5 votes vote down vote up
protected void addValueMarker(final JFreeChart chart, final double position, final String label) {
	final ValueMarker marker = new ValueMarker(position);
	marker.setPaint(Color.black);
	marker.setLabel(label);
	final XYPlot plot = (XYPlot) chart.getPlot();
	plot.addDomainMarker(marker);
}
 
Example 13
Source File: HistogramChartFactory.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds annotations to the Gaussian fit parameters
 * 
 * @param plot
 * @param fit Gaussian fit {normalisation factor, mean, sigma}
 */
public static void addGaussianFitAnnotations(XYPlot plot, double[] fit) {
  Paint c = plot.getDomainCrosshairPaint();
  BasicStroke s = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1,
      new float[] {5f, 2.5f}, 0);

  plot.addDomainMarker(new ValueMarker(fit[1], c, s));
  plot.addDomainMarker(new ValueMarker(fit[1] - fit[2], c, s));
  plot.addDomainMarker(new ValueMarker(fit[1] + fit[2], c, s));
}
 
Example 14
Source File: GUIUtils.java    From egads with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Add anomalies to the plot.
 */
public void addAnomalies(XYPlot plot, ArrayList<Anomaly> anomalyList) {
    for (Anomaly a : anomalyList) {
        IntervalSequence is = a.intervals;
        for (Interval i : is) {
        	ValueMarker marker = new ValueMarker(i.index);
            marker.setPaint(Color.black);
            plot.addDomainMarker(marker);
        }
    }
}
 
Example 15
Source File: HistogramChartFactory.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds annotations to the Gaussian fit parameters
 * 
 * @param plot
 * @param fit Gaussian fit {normalisation factor, mean, sigma}
 */
public static void addGaussianFitAnnotations(XYPlot plot, double[] fit) {
  Paint c = plot.getDomainCrosshairPaint();
  BasicStroke s = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1,
      new float[] {5f, 2.5f}, 0);

  plot.addDomainMarker(new ValueMarker(fit[1], c, s));
  plot.addDomainMarker(new ValueMarker(fit[1] - fit[2], c, s));
  plot.addDomainMarker(new ValueMarker(fit[1] + fit[2], c, s));
}
 
Example 16
Source File: cfCHART.java    From openbd-core with GNU General Public License v3.0 4 votes vote down vote up
public void addDomainMarker(XYPlot plot, cfCHARTDOMAINMARKERData dmData) throws cfmRunTimeException {
	double dbl;
	try {
		dbl = Double.parseDouble(dmData.getValue());
	} catch (NumberFormatException nfe) {
		throw newRunTimeException("the CFCHARTDOMAINMARKER value attribute must be numeric for scale charts");
	}
	ValueMarker domainMarker = new ValueMarker(dbl);
	boolean drawAsLine = true; // XY charts currently only support drawing
															// domain markers as lines
	domainMarker.setPaint(convertStringToColor(dmData.getColor()));
	if (dmData.getLabel() != null) {
		domainMarker.setLabel(dmData.getLabel());
		domainMarker.setLabelPaint(convertStringToColor(dmData.getLabelColor()));
		String labelPos = dmData.getLabelPosition();
		if (labelPos.equals("top_left")) {
			domainMarker.setLabelAnchor(RectangleAnchor.TOP_LEFT);
			if (drawAsLine)
				domainMarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
			else
				domainMarker.setLabelTextAnchor(TextAnchor.TOP_LEFT);
		} else if (labelPos.equals("top")) {
			domainMarker.setLabelAnchor(RectangleAnchor.TOP);
			domainMarker.setLabelTextAnchor(TextAnchor.TOP_CENTER);
		} else if (labelPos.equals("top_right")) {
			domainMarker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
			if (drawAsLine)
				domainMarker.setLabelTextAnchor(TextAnchor.TOP_LEFT);
			else
				domainMarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
		} else if (labelPos.equals("left")) {
			domainMarker.setLabelAnchor(RectangleAnchor.LEFT);
			if (drawAsLine)
				domainMarker.setLabelTextAnchor(TextAnchor.CENTER_RIGHT);
			else
				domainMarker.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
		} else if (labelPos.equals("center")) {
			domainMarker.setLabelAnchor(RectangleAnchor.CENTER);
			domainMarker.setLabelTextAnchor(TextAnchor.CENTER);
		} else if (labelPos.equals("right")) {
			domainMarker.setLabelAnchor(RectangleAnchor.RIGHT);
			if (drawAsLine)
				domainMarker.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
			else
				domainMarker.setLabelTextAnchor(TextAnchor.CENTER_RIGHT);
		} else if (labelPos.equals("bottom_left")) {
			domainMarker.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT);
			if (drawAsLine)
				domainMarker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
			else
				domainMarker.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT);
		} else if (labelPos.equals("bottom")) {
			domainMarker.setLabelAnchor(RectangleAnchor.BOTTOM);
			domainMarker.setLabelTextAnchor(TextAnchor.BOTTOM_CENTER);
		} else if (labelPos.equals("bottom_right")) {
			domainMarker.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
			if (drawAsLine)
				domainMarker.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT);
			else
				domainMarker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
		}
		domainMarker.setLabelOffsetType(LengthAdjustmentType.NO_CHANGE);
		domainMarker.setLabelFont(getFont(dmData.getFont(), dmData.getFontBold(), dmData.getFontItalic(), dmData.getFontSize()));
	}
	plot.addDomainMarker(domainMarker, Layer.BACKGROUND);
}
 
Example 17
Source File: MultiSpectraVisualizerWindow.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
private JPanel addSpectra(int scan) {
  JPanel panel = new JPanel(new BorderLayout());
  // Split pane for eic plot (top) and spectrum (bottom)
  JSplitPane bottomPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);

  // Create EIC plot
  // labels for TIC visualizer
  Map<Feature, String> labelsMap = new HashMap<Feature, String>(0);

  Feature peak = row.getPeak(activeRaw);

  // scan selection
  ScanSelection scanSelection = new ScanSelection(activeRaw.getDataRTRange(1), 1);

  // mz range
  Range<Double> mzRange = null;
  mzRange = peak.getRawDataPointsMZRange();
  // optimize output by extending the range
  double upper = mzRange.upperEndpoint();
  double lower = mzRange.lowerEndpoint();
  double fiveppm = (upper * 5E-6);
  mzRange = Range.closed(lower - fiveppm, upper + fiveppm);

  // labels
  labelsMap.put(peak, peak.toString());

  // get EIC window
  TICVisualizerWindow window = new TICVisualizerWindow(new RawDataFile[] {activeRaw}, // raw
      TICPlotType.BASEPEAK, // plot type
      scanSelection, // scan selection
      mzRange, // mz range
      new Feature[] {peak}, // selected features
      labelsMap); // labels

  // get EIC Plot
  TICPlot ticPlot = window.getTICPlot();
  ticPlot.setPreferredSize(new Dimension(600, 200));
  ticPlot.getChart().getLegend().setVisible(false);

  // add a retention time Marker to the EIC
  ValueMarker marker = new ValueMarker(activeRaw.getScan(scan).getRetentionTime());
  marker.setPaint(Color.RED);
  marker.setStroke(new BasicStroke(3.0f));

  XYPlot plot = (XYPlot) ticPlot.getChart().getPlot();
  plot.addDomainMarker(marker);
  bottomPane.add(ticPlot);
  bottomPane.setResizeWeight(0.5);
  bottomPane.setEnabled(true);
  bottomPane.setDividerSize(5);
  bottomPane.setDividerLocation(200);

  JSplitPane spectrumPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);

  // get MS/MS spectra window
  SpectraVisualizerWindow spectraWindow = new SpectraVisualizerWindow(activeRaw);
  spectraWindow.loadRawData(activeRaw.getScan(scan));

  // get MS/MS spectra plot
  SpectraPlot spectrumPlot = spectraWindow.getSpectrumPlot();
  spectrumPlot.getChart().getLegend().setVisible(false);
  spectrumPlot.setPreferredSize(new Dimension(600, 400));
  spectrumPane.add(spectrumPlot);
  spectrumPane.add(spectraWindow.getToolBar());
  spectrumPane.setResizeWeight(1);
  spectrumPane.setEnabled(false);
  spectrumPane.setDividerSize(0);
  bottomPane.add(spectrumPane);
  panel.add(bottomPane);
  panel.setBorder(BorderFactory.createLineBorder(Color.black));
  return panel;
}
 
Example 18
Source File: JPanelProfil.java    From Course_Generator with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Update the profil chart
 */
public void RefreshProfilChart() {
	if (track == null)
		return;
	if (track.data.isEmpty())
		return;

	// -- Clear all series
	if (datasetProfil.getSeriesCount() > 0)
		datasetProfil.removeAllSeries();

	XYPlot plot = chartProfil.getXYPlot();
	plot.clearDomainMarkers();

	// -- Populate the serie
	XYSeries serie1 = new XYSeries("Elevation/Distance");
	int cmpt = 1;
	for (CgData r : track.data) {
		double x = r.getTotal(settings.Unit) / 1000;
		double y = r.getElevation(settings.Unit);
		serie1.add(x, y);

		if (((r.getTag() & CgConst.TAG_MARK) != 0) & showProfilMarker) {
			Marker m = new ValueMarker(x);
			m.setPaint(Color.GRAY);
			m.setLabelFont(new Font("SansSerif", Font.PLAIN, 10));
			m.setLabel(String.valueOf(cmpt));
			m.setLabelOffset(new RectangleInsets(5, 0, 0, 2));
			m.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
			m.setLabelTextAnchor(TextAnchor.TOP_LEFT);
			plot.addDomainMarker(m);
			cmpt++;
		}
	}
	datasetProfil.addSeries(serie1);

	if (track.getMaxElev(settings.Unit) > track.getMinElev(settings.Unit)) {
		// XYPlot plot = chart.getXYPlot();
		ValueAxis axisY = plot.getRangeAxis();
		axisY.setRange(Math.floor(track.getMinElev(settings.Unit) / 100.0) * 100.0,
				Math.ceil(track.getMaxElev(settings.Unit) / 100.0) * 100.0);
	}
}
 
Example 19
Source File: MultiSpectraVisualizerWindow.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
private JPanel addSpectra(int scan) {
  JPanel panel = new JPanel(new BorderLayout());
  // Split pane for eic plot (top) and spectrum (bottom)
  JSplitPane bottomPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);

  // Create EIC plot
  // labels for TIC visualizer
  Map<Feature, String> labelsMap = new HashMap<Feature, String>(0);

  Feature peak = row.getPeak(activeRaw);

  // scan selection
  ScanSelection scanSelection = new ScanSelection(activeRaw.getDataRTRange(1), 1);

  // mz range
  Range<Double> mzRange = null;
  mzRange = peak.getRawDataPointsMZRange();
  // optimize output by extending the range
  double upper = mzRange.upperEndpoint();
  double lower = mzRange.lowerEndpoint();
  double fiveppm = (upper * 5E-6);
  mzRange = Range.closed(lower - fiveppm, upper + fiveppm);

  // labels
  labelsMap.put(peak, peak.toString());

  // get EIC window
  TICVisualizerWindow window = new TICVisualizerWindow(new RawDataFile[] {activeRaw}, // raw
      TICPlotType.BASEPEAK, // plot type
      scanSelection, // scan selection
      mzRange, // mz range
      null,
      // new Feature[] {peak}, // selected features
      labelsMap); // labels

  // get EIC Plot
  TICPlot ticPlot = window.getTICPlot();
  // ticPlot.setPreferredSize(new Dimension(600, 200));
  ticPlot.getChart().getLegend().setVisible(false);

  // add a retention time Marker to the EIC
  ValueMarker marker = new ValueMarker(activeRaw.getScan(scan).getRetentionTime());
  marker.setPaint(Color.RED);
  marker.setStroke(new BasicStroke(3.0f));

  XYPlot plot = (XYPlot) ticPlot.getChart().getPlot();
  plot.addDomainMarker(marker);
  // bottomPane.add(ticPlot);
  bottomPane.setResizeWeight(0.5);
  bottomPane.setEnabled(true);
  bottomPane.setDividerSize(5);
  bottomPane.setDividerLocation(200);

  JSplitPane spectrumPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);

  // get MS/MS spectra window
  SpectraVisualizerWindow spectraWindow = new SpectraVisualizerWindow(activeRaw);
  spectraWindow.loadRawData(activeRaw.getScan(scan));

  // get MS/MS spectra plot
  SpectraPlot spectrumPlot = spectraWindow.getSpectrumPlot();
  spectrumPlot.getChart().getLegend().setVisible(false);
  // spectrumPlot.setPreferredSize(new Dimension(600, 400));
  // spectrumPane.add(spectrumPlot);
  // spectrumPane.add(spectraWindow.getToolBar());
  spectrumPane.setResizeWeight(1);
  spectrumPane.setEnabled(false);
  spectrumPane.setDividerSize(0);
  bottomPane.add(spectrumPane);
  panel.add(bottomPane);
  panel.setBorder(BorderFactory.createLineBorder(Color.black));
  return panel;
}
 
Example 20
Source File: AnomalyGraphGenerator.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a chart containing the current/baseline data (in that order) as well as markers for
 * each anomaly interval. timeGranularity and windowMillis are used to determine the date format
 * and spacing for tick marks on the domain (x) axis.
 */
public JFreeChart createChart(final XYDataset dataset, final String metric,
    final TimeGranularity timeGranularity, final long windowMillis,
    final Map<MergedAnomalyResultDTO, String> anomaliesWithLabels) {

  // create the chart...
  final JFreeChart chart = ChartFactory.createTimeSeriesChart(null, // no chart title for email
                                                                    // image
      "Date (" + DEFAULT_TIME_ZONE.getID() + ")", // x axis label
      metric, // y axis label
      dataset, // data
      true, // include legend
      false, // tooltips - n/a if the chart will be saved as an img
      false // urls - n/a if the chart will be saved as an img
  );

  // get a reference to the plot for further customisation...
  final XYPlot plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setDomainGridlinesVisible(false);
  plot.setRangeGridlinesVisible(false);

  // dashboard webapp currently uses solid blue for current and dashed blue for baseline
  // (5/2/2016)
  final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
  renderer.setSeriesShapesVisible(0, false);
  renderer.setSeriesShapesVisible(1, false);
  renderer.setSeriesPaint(0, Color.BLUE);
  renderer.setSeriesPaint(1, Color.BLUE);
  // http://www.java2s.com/Code/Java/Chart/JFreeChartLineChartDemo5showingtheuseofacustomdrawingsupplier.htm
  // set baseline to be dashed
  renderer.setSeriesStroke(1,
      new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] {
          2.0f, 6.0f
      }, 0.0f));
  plot.setRenderer(renderer);

  DateAxis axis = (DateAxis) plot.getDomainAxis();
  DateTickUnit dateTickUnit = getDateTickUnit(timeGranularity, windowMillis);
  SimpleDateFormat dateFormat = getDateFormat(timeGranularity);
  axis.setDateFormatOverride(dateFormat);
  axis.setTickUnit(dateTickUnit);
  axis.setVerticalTickLabels(true);

  List<Marker> anomalyIntervals = getAnomalyIntervals(anomaliesWithLabels);
  for (Marker marker : anomalyIntervals) {
    plot.addDomainMarker(marker);
  }

  return chart;

}