List of usage examples for org.jfree.chart.annotations XYPointerAnnotation setLabelOffset
public void setLabelOffset(double offset)
From source file:org.jfree.chart.demo.NormalDistributionDemo2.java
public static JFreeChart createChart(XYDataset xydataset) { JFreeChart jfreechart = ChartFactory.createXYLineChart("Normal Distribution Demo 2", "X", "Y", xydataset, PlotOrientation.VERTICAL, true, true, false); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setDomainZeroBaselineVisible(true); xyplot.setRangeZeroBaselineVisible(true); xyplot.setDomainPannable(true);/* w w w . j ava 2 s . c o m*/ xyplot.setRangePannable(true); ValueAxis valueaxis = xyplot.getDomainAxis(); valueaxis.setLowerMargin(0.0D); valueaxis.setUpperMargin(0.0D); XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer(); xylineandshaperenderer.setDrawSeriesLineAsPath(true); xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(1.5F)); xylineandshaperenderer.setSeriesStroke(1, new BasicStroke(2.0F, 1, 1, 1.0F, new float[] { 6F, 4F }, 0.0F)); xylineandshaperenderer.setSeriesStroke(2, new BasicStroke(2.0F, 1, 1, 1.0F, new float[] { 6F, 4F, 3F, 3F }, 0.0F)); xylineandshaperenderer.setSeriesStroke(3, new BasicStroke(2.0F, 1, 1, 1.0F, new float[] { 4F, 4F }, 0.0F)); XYPointerAnnotation xypointerannotation = new XYPointerAnnotation(" = -2.0, \262 = 0.5", -2D, 0.56399999999999995D, 3.9269908169872414D); xypointerannotation.setLabelOffset(4D); xypointerannotation.setTextAnchor(TextAnchor.BOTTOM_RIGHT); xypointerannotation.setBackgroundPaint(Color.yellow); xyplot.addAnnotation(xypointerannotation); XYPointerAnnotation xypointerannotation1 = new XYPointerAnnotation(" = 0.0, \262 = 0.2", 0.22500000000000001D, 0.80000000000000004D, 0.0D); xypointerannotation1.setLabelOffset(4D); xypointerannotation1.setTextAnchor(TextAnchor.CENTER_LEFT); xypointerannotation1.setBackgroundPaint(new Color(0, 0, 255, 63)); xyplot.addAnnotation(xypointerannotation1); XYPointerAnnotation xypointerannotation2 = new XYPointerAnnotation(" = 0.0, \262 = 1.0", 0.75D, 0.29999999999999999D, 5.497787143782138D); xypointerannotation2.setLabelOffset(4D); xypointerannotation2.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT); xypointerannotation2.setBackgroundPaint(new Color(255, 0, 0, 63)); xyplot.addAnnotation(xypointerannotation2); XYPointerAnnotation xypointerannotation3 = new XYPointerAnnotation(" = 0.0, \262 = 5.0", 3D, 0.074999999999999997D, 4.7123889803846897D); xypointerannotation3.setLabelOffset(4D); xypointerannotation3.setTextAnchor(TextAnchor.BOTTOM_CENTER); xypointerannotation3.setBackgroundPaint(new Color(0, 255, 0, 63)); xyplot.addAnnotation(xypointerannotation3); return jfreechart; }
From source file:org.owasp.benchmark.score.report.Scatter.java
private XYPointerAnnotation makePointer(int x, int y, String msg, TextAnchor anchor, int angle) { XYPointerAnnotation pointer = new XYPointerAnnotation(msg, x, y, Math.toRadians(angle)); pointer.setBackgroundPaint(Color.white); pointer.setTextAnchor(anchor);// w ww . j a v a 2 s . c o m pointer.setArrowWidth(4); pointer.setArrowLength(8); pointer.setArrowPaint(Color.red); pointer.setLabelOffset(2); pointer.setPaint(Color.red); pointer.setFont(theme.getRegularFont()); return pointer; }
From source file:org.trade.ui.chart.CandlestickChart.java
/** * Method addBuySellTradeArrow.//from ww w .ja v a2s. c o m * * @param action * String * @param price * Money * @param time * Date * @param quantity * Integer * @throws ValueTypeException */ public void addBuySellTradeArrow(String action, Money price, Date time, Integer quantity) throws ValueTypeException { String label = Action.newInstance(action) + " " + quantity + "@" + price; XYPointerAnnotation arrow = new XYPointerAnnotation(label, time.getTime(), price.doubleValue(), 90d); arrow.setLabelOffset(5.0); arrow.setBackgroundPaint(Color.GREEN); if (action.equals(Action.SELL)) { arrow.setAngle(-90d); arrow.setBackgroundPaint(Color.RED); } CombinedDomainXYPlot combinedXYplot = (CombinedDomainXYPlot) this.chart.getPlot(); @SuppressWarnings("unchecked") List<XYPlot> subplots = combinedXYplot.getSubplots(); XYPlot xyplot = subplots.get(0); xyplot.addAnnotation(arrow); this.chart.fireChartChanged(); }
From source file:net.sf.maltcms.chromaui.charts.Chromatogram1DChartProvider.java
/** * * @param f//from w w w.j ava 2 s .c o m * @param useScanAcquisitionTime * @param valueVariable * @return */ public List<XYPointerAnnotation> getANDIChromPeakAnnotations(IFileFragment f, boolean useScanAcquisitionTime, String valueVariable) { List<XYPointerAnnotation> l = new ArrayList<>(); try { IVariableFragment peakNames = f.getChild("peak_name"); IVariableFragment peakRT = f.getChild("peak_retention_time"); Array ordinateValues = f.getChild(valueVariable).getArray(); double delay = f.getChild("actual_delay_time").getArray().getDouble(0); double samplingRate = f.getChild("actual_sampling_interval").getArray().getDouble(0); Index idx = ordinateValues.getIndex(); Collection<String> peaknames = ArrayTools.getStringsFromArray(peakNames.getArray()); IndexIterator ii = peakRT.getArray().getIndexIterator(); Iterator<String> peaknamesIter = peaknames.iterator(); while (ii.hasNext() && peaknamesIter.hasNext()) { double sat = ii.getDoubleNext(); int scan = (int) (Math.floor(((sat - delay) / samplingRate))); String name = peaknamesIter.next(); if (name.trim().isEmpty()) { name = "NN"; } if (useScanAcquisitionTime) { XYPointerAnnotation xypa = new XYPointerAnnotation(name, sat, ordinateValues.getDouble(idx.set(scan)), -0.8); xypa.setTipRadius(0.01); xypa.setLabelOffset(1); xypa.setBaseRadius(10); xypa.setTextAnchor(TextAnchor.BOTTOM_LEFT); l.add(xypa); // XYLineAnnotation baseline = new XYLineAnnotation(); } else { XYPointerAnnotation xypa = new XYPointerAnnotation(name, scan, ordinateValues.getDouble(idx.set(scan)), -0.8); xypa.setTipRadius(0.01); xypa.setLabelOffset(1); xypa.setBaseRadius(10); xypa.setTextAnchor(TextAnchor.BOTTOM_LEFT); l.add(xypa); } } } catch (ResourceNotAvailableException rnae) { } return l; }
From source file:net.sf.maltcms.chromaui.charts.Chromatogram1DChartProvider.java
/** * * @param f// w w w . ja v a 2s . co m * @param ordinateValues * @param useScanAcquisitionTime * @return */ public List<XYPointerAnnotation> getCSVPeakAnnotations(IFileFragment f, Array ordinateValues, boolean useScanAcquisitionTime) { List<XYPointerAnnotation> l = new ArrayList<>(); try { String basename = StringTools.removeFileExt(f.getName()); File peakAnnotations = new File(new File(f.getAbsolutePath()).getParentFile(), basename + ".csv"); Logger.getLogger(Chromatogram1DChartProvider.class.getName()).log(Level.INFO, "Looking for file {0}", peakAnnotations); if (!peakAnnotations.exists()) { Logger.getLogger(Chromatogram1DChartProvider.class.getName()).info("File does not exist!"); return l; } Logger.getLogger(Chromatogram1DChartProvider.class.getName()).info("File exists!"); CSVReader csvr = new CSVReader(); try { Tuple2D<Vector<Vector<String>>, Vector<String>> t = csvr .read(new BufferedInputStream(new FileInputStream(peakAnnotations))); HashMap<String, Vector<String>> hm = csvr.getColumns(t); Vector<String> rt = hm.get("RT"); Vector<String> scan = hm.get("SCAN"); int i = 0; Vector<String> id = hm.get("NO"); for (String s : rt) { XYPointerAnnotation xypa = null; //correct chemstation scan index by -1 (1 based) int scanIdx = Integer.parseInt(scan.get(i)) - 1; double apex = ordinateValues.getDouble(scanIdx); if (useScanAcquisitionTime) { double srt = (Double.parseDouble(s)); xypa = new XYPointerAnnotation(id.get(i), srt * 60.0, apex, -0.8); } else { xypa = new XYPointerAnnotation(id.get(i), scanIdx, apex, -0.8); } xypa.setTipRadius(0.01); xypa.setLabelOffset(1); xypa.setBaseRadius(10); xypa.setTextAnchor(TextAnchor.BOTTOM_LEFT); l.add(xypa); Logger.getLogger(Chromatogram1DChartProvider.class.getName()).log(Level.INFO, "Adding annotation at: {0}", xypa.getX()); i++; } } catch (FileNotFoundException ex) { Exceptions.printStackTrace(ex); } } catch (ResourceNotAvailableException rnae) { } return l; }