List of usage examples for org.jfree.chart.annotations XYTextAnnotation setRotationAngle
public void setRotationAngle(double angle)
From source file:org.jfree.chart.demo.CombinedXYPlotDemo1.java
/** * Creates a combined chart.//from www .ja v a 2 s . com * * @return the combined chart. */ private JFreeChart createCombinedChart() { // create subplot 1... final XYDataset data1 = createDataset1(); final XYItemRenderer renderer1 = new StandardXYItemRenderer(); final NumberAxis rangeAxis1 = new NumberAxis("Range 1"); final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1); subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); final XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 50.0, 10000.0); annotation.setFont(new Font("SansSerif", Font.PLAIN, 9)); annotation.setRotationAngle(Math.PI / 4.0); subplot1.addAnnotation(annotation); // create subplot 2... final XYDataset data2 = createDataset2(); final XYItemRenderer renderer2 = new StandardXYItemRenderer(); final NumberAxis rangeAxis2 = new NumberAxis("Range 2"); rangeAxis2.setAutoRangeIncludesZero(false); final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2); subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); // parent plot... final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain")); plot.setGap(10.0); // add the subplots... plot.add(subplot1, 1); plot.add(subplot2, 1); plot.setOrientation(PlotOrientation.VERTICAL); // return a new chart containing the overlaid plot... return new JFreeChart("CombinedDomainXYPlot Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, true); }
From source file:org.activequant.util.charting.Chart.java
public XYTextAnnotation getUpArrow(double x, double y) { XYTextAnnotation arrow = new XYTextAnnotation(">", x, y); arrow.setRotationAngle(Math.PI * 1.5); arrow.setFont(new Font("SansSerif", Font.BOLD, 9)); return arrow; }
From source file:org.activequant.util.charting.Chart.java
public XYTextAnnotation getDownArrow(double x, double y) { XYTextAnnotation arrow = new XYTextAnnotation(">", x, y); arrow.setRotationAngle(Math.PI * 0.5); arrow.setFont(new Font("SansSerif", Font.BOLD, 9)); return arrow; }
From source file:org.jfree.chart.demo.CombinedXYPlotDemo4.java
/** * Creates a combined chart.//from ww w . j av a 2 s .com * * @return The combined chart. */ private JFreeChart createCombinedChart() { // create subplot 1... final XYDataset data1 = createDataset1(); final XYItemRenderer renderer1 = new StandardXYItemRenderer(); final NumberAxis rangeAxis1 = new NumberAxis("Range 1"); final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1); subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); // add secondary axis subplot1.setDataset(1, createDataset2()); final NumberAxis axis2 = new NumberAxis("Range Axis 2"); axis2.setAutoRangeIncludesZero(false); subplot1.setRangeAxis(1, axis2); subplot1.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); subplot1.setRenderer(1, new StandardXYItemRenderer()); subplot1.mapDatasetToRangeAxis(1, 1); final XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 50.0, 10000.0); annotation.setFont(new Font("SansSerif", Font.PLAIN, 9)); annotation.setRotationAngle(Math.PI / 4.0); subplot1.addAnnotation(annotation); // create subplot 2... final XYDataset data2 = createDataset2(); final XYItemRenderer renderer2 = new StandardXYItemRenderer(); final NumberAxis rangeAxis2 = new NumberAxis("Range 2"); rangeAxis2.setAutoRangeIncludesZero(false); final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2); subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); // parent plot... final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain")); plot.setGap(10.0); // add the subplots... plot.add(subplot1, 1); plot.add(subplot2, 1); plot.setOrientation(PlotOrientation.VERTICAL); // return a new chart containing the overlaid plot... return new JFreeChart("CombinedDomainXYPlot Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, true); }
From source file:org.jgrasstools.gears.utils.chart.Scatter.java
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);// ww w . j a v a2 s. c o m 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); }
From source file:org.zaproxy.zap.extension.ascan.ScanProgressDialog.java
/** * Update the current Scan progress and//w w w . ja va 2 s . c o m * prepare actions and scan summary */ private void showProgress() { // Start panel data settings HostProcess hp = getSelectedHostProcess(); if (scan.getHostProcesses() != null && hp != null) { // Update the main table entries model.updateValues(scan, hp); if (scan.isStopped()) { this.stopThread = true; } if (chart != null) { ResponseCountSnapshot snapshot = scan.getRequestHistory(); while (snapshot != null) { try { Second second = new Second(snapshot.getDate()); this.seriesTotal.add(second, snapshot.getTotal()); this.series100.add(second, snapshot.getResp100()); this.series200.add(second, snapshot.getResp200()); this.series300.add(second, snapshot.getResp300()); this.series400.add(second, snapshot.getResp400()); this.series500.add(second, snapshot.getResp500()); snapshot = scan.getRequestHistory(); for (Plugin plugin : scan.getHostProcesses().get(0).getRunning()) { if (!labelsAdded.contains(plugin.getName())) { // Add a vertical line with the plugin name ValueMarker vm = new ValueMarker(plugin.getTimeStarted().getTime()); double center = chart.getXYPlot().getRangeAxis().getRange().getCentralValue(); if (lastCentre != center) { if (lastCentre != -1) { // Move the existing labels so they stay in the centre @SuppressWarnings("rawtypes") List annotations = chart.getXYPlot().getAnnotations(); for (Object o : annotations) { if (o instanceof XYTextAnnotation) { XYTextAnnotation annotation = (XYTextAnnotation) o; annotation.setY(center); } } } lastCentre = center; } XYTextAnnotation updateLabel = new XYTextAnnotation(plugin.getName(), plugin.getTimeStarted().getTime(), center); updateLabel.setFont(FontUtils.getFont("Sans Serif")); updateLabel.setRotationAnchor(TextAnchor.BASELINE_CENTER); updateLabel.setTextAnchor(TextAnchor.BASELINE_CENTER); updateLabel.setRotationAngle(-3.14 / 2); updateLabel.setPaint(Color.black); chart.getXYPlot().addDomainMarker(vm, Layer.BACKGROUND); chart.getXYPlot().addAnnotation(updateLabel); labelsAdded.add(plugin.getName()); } } } catch (Exception e) { log.error(e.getMessage(), e); } } } } }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.scattercharts.MarkerScatter.java
public JFreeChart createChart(DatasetMap datasets) { DefaultXYDataset dataset = (DefaultXYDataset) datasets.getDatasets().get("1"); JFreeChart chart = ChartFactory.createScatterPlot(name, yLabel, xLabel, dataset, PlotOrientation.HORIZONTAL, false, true, false);/*w w w .j a va 2s . c o m*/ TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); chart.setBackgroundPaint(Color.white); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } XYPlot plot = (XYPlot) chart.getPlot(); plot.setForegroundAlpha(0.65f); XYItemRenderer renderer = plot.getRenderer(); //defines colors int seriesN = dataset.getSeriesCount(); if ((colorMap != null && colorMap.size() > 0) || (defaultColor != null && !defaultColor.equals(""))) { for (int i = 0; i < seriesN; i++) { String serieName = (String) dataset.getSeriesKey(i); Color color = new Color(Integer.decode(defaultColor).intValue()); if (colorMap != null && colorMap.size() > 0) color = (Color) colorMap.get(serieName); if (color != null) renderer.setSeriesPaint(i, color); } } // add un interval marker for the Y axis... if (yMarkerStartInt != null && yMarkerEndInt != null && !yMarkerStartInt.equals("") && !yMarkerEndInt.equals("")) { Marker intMarkerY = new IntervalMarker(Double.parseDouble(yMarkerStartInt), Double.parseDouble(yMarkerEndInt)); intMarkerY.setLabelOffsetType(LengthAdjustmentType.EXPAND); intMarkerY.setPaint( new Color(Integer.decode((yMarkerIntColor.equals("")) ? "0" : yMarkerIntColor).intValue())); //intMarkerY.setLabel(yMarkerLabel); intMarkerY.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); intMarkerY.setLabelTextAnchor(TextAnchor.TOP_RIGHT); plot.addDomainMarker(intMarkerY, Layer.BACKGROUND); } // add un interval marker for the X axis... if (xMarkerStartInt != null && xMarkerEndInt != null && !xMarkerStartInt.equals("") && !xMarkerEndInt.equals("")) { Marker intMarkerX = new IntervalMarker(Double.parseDouble(xMarkerStartInt), Double.parseDouble(xMarkerEndInt)); intMarkerX.setLabelOffsetType(LengthAdjustmentType.EXPAND); intMarkerX.setPaint( new Color(Integer.decode((xMarkerIntColor.equals("")) ? "0" : xMarkerIntColor).intValue())); //intMarkerX.setLabel(xMarkerLabel); intMarkerX.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); intMarkerX.setLabelTextAnchor(TextAnchor.TOP_RIGHT); plot.addRangeMarker(intMarkerX, Layer.BACKGROUND); } // add a labelled marker for the Y axis... if (yMarkerValue != null && !yMarkerValue.equals("")) { Marker markerY = new ValueMarker(Double.parseDouble(yMarkerValue)); markerY.setLabelOffsetType(LengthAdjustmentType.EXPAND); if (!yMarkerColor.equals("")) markerY.setPaint(new Color(Integer.decode(yMarkerColor).intValue())); markerY.setLabel(yMarkerLabel); markerY.setLabelFont(new Font("Arial", Font.BOLD, 11)); markerY.setLabelAnchor(RectangleAnchor.TOP_RIGHT); markerY.setLabelTextAnchor(TextAnchor.TOP_RIGHT); plot.addDomainMarker(markerY, Layer.BACKGROUND); } // add a labelled marker for the X axis... if (xMarkerValue != null && !xMarkerValue.equals("")) { Marker markerX = new ValueMarker(Double.parseDouble(xMarkerValue)); markerX.setLabelOffsetType(LengthAdjustmentType.EXPAND); if (!xMarkerColor.equals("")) markerX.setPaint(new Color(Integer.decode(xMarkerColor).intValue())); markerX.setLabel(xMarkerLabel); markerX.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); markerX.setLabelTextAnchor(TextAnchor.TOP_RIGHT); plot.addRangeMarker(markerX, Layer.BACKGROUND); } if (xRangeLow != null && !xRangeLow.equals("") && xRangeHigh != null && !xRangeHigh.equals("")) { if (Double.valueOf(xRangeLow).doubleValue() > xMin) xRangeLow = String.valueOf(xMin); if (Double.valueOf(xRangeHigh).doubleValue() < xMax) xRangeHigh = String.valueOf(xMax); ValueAxis rangeAxis = plot.getRangeAxis(); //rangeAxis.setRange(Double.parseDouble(xRangeLow), Double.parseDouble(xRangeHigh)); rangeAxis.setRangeWithMargins(Double.parseDouble(xRangeLow), Double.parseDouble(xRangeHigh)); } else { NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRange(true); rangeAxis.setRange(xMin, xMax); } if (yRangeLow != null && !yRangeLow.equals("") && yRangeHigh != null && !yRangeHigh.equals("")) { if (Double.valueOf(yRangeLow).doubleValue() > yMin) yRangeLow = String.valueOf(yMin); if (Double.valueOf(yRangeHigh).doubleValue() < yMax) yRangeHigh = String.valueOf(yMax); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); //domainAxis.setRange(Double.parseDouble(yRangeLow), Double.parseDouble(yRangeHigh)); domainAxis.setRangeWithMargins(Double.parseDouble(yRangeLow), Double.parseDouble(yRangeHigh)); domainAxis.setAutoRangeIncludesZero(false); } else { NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRange(true); domainAxis.setRange(yMin, yMax); domainAxis.setAutoRangeIncludesZero(false); } //add annotations if requested if (viewAnnotations != null && viewAnnotations.equalsIgnoreCase("true")) { if (annotationMap == null || annotationMap.size() == 0) logger.error("Annotations on the chart are requested but the annotationMap is null!"); else { int cont = 1; for (Iterator iterator = annotationMap.keySet().iterator(); iterator.hasNext();) { String text = (String) iterator.next(); String pos = (String) annotationMap.get(text); double x = Double.parseDouble(pos.substring(0, pos.indexOf("__"))); double y = Double.parseDouble(pos.substring(pos.indexOf("__") + 2)); //default up position XYTextAnnotation annotation = new XYTextAnnotation(text, y - 1, x + ((text.length() > 20) ? text.length() / 3 + 1 : text.length() / 2 + 1)); if (cont % 2 != 0) //dx annotation = new XYTextAnnotation(text, y, x + ((text.length() > 20) ? text.length() / 3 + 1 : text.length() / 2 + 1)); else //sx //annotation = new XYTextAnnotation(text, y, x-((text.length()%2==0)?text.length():text.length()-1)); annotation = new XYTextAnnotation(text, y, x - (text.length() - 1)); annotation.setFont(new Font("SansSerif", Font.PLAIN, 11)); //annotation.setRotationAngle(Math.PI / 4.0); annotation.setRotationAngle(0.0); // horizontal plot.addAnnotation(annotation); cont++; } renderer.setShape(new Ellipse2D.Double(-3, -5, 8, 8)); } } else if (viewAnnotations != null && viewAnnotations.equalsIgnoreCase("false")) { renderer.setShape(new Ellipse2D.Double(-3, -5, 8, 8)); } if (legend == true) { drawLegend(chart); } return chart; }
From source file:org.operamasks.faces.render.graph.ChartRenderer.java
private XYTextAnnotation createXYTextAnnotation(UITextAnnotation at, double x, double y) { XYTextAnnotation result; if (at.isDrawArrow()) { Double angle = at.getArrowAngle(); if (angle == null) angle = 0.0;//from w ww . ja v a2s . co m XYPointerAnnotation pointer = new XYPointerAnnotation(at.getText(), x, y, angle * Math.PI / 180.0); Double length = at.getArrowLength(); if (length != null) { pointer.setBaseRadius(length); } Paint arrowColor = at.getArrowColor(); if (arrowColor == null) arrowColor = at.getColor(); if (arrowColor != null) pointer.setArrowPaint(arrowColor); result = pointer; } else { result = new XYTextAnnotation(at.getText(), x, y); } Font font = at.getFont(); if (font != null) { result.setFont(font); } Paint color = at.getColor(); if (color != null) { result.setPaint(color); } TextAnchor anchor = getTextAnchor(at.getAnchor()); if (anchor != null) { result.setTextAnchor(anchor); } Double rotationAngle = at.getRotationAngle(); if (rotationAngle != null) { result.setRotationAngle(rotationAngle * Math.PI / 180.0); } return result; }