List of usage examples for org.jfree.chart.annotations XYTextAnnotation setTextAnchor
public void setTextAnchor(TextAnchor anchor)
From source file:org.jfree.chart.demo.AnnotationDemo1.java
private static JFreeChart createChart(XYDataset xydataset) { JFreeChart jfreechart = ChartFactory.createXYLineChart(null, "Age in Months", "Weight (kg)", xydataset, PlotOrientation.VERTICAL, true, true, false); TextTitle texttitle = new TextTitle("Growth Charts: United States", new Font("SansSerif", 1, 14)); TextTitle texttitle1 = new TextTitle("Weight-for-age percentiles: boys, birth to 36 months", new Font("SansSerif", 0, 11)); jfreechart.addSubtitle(texttitle);//w w w .java 2s. c o m jfreechart.addSubtitle(texttitle1); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis(); numberaxis.setUpperMargin(0.12D); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); NumberAxis numberaxis1 = (NumberAxis) xyplot.getRangeAxis(); numberaxis1.setAutoRangeIncludesZero(false); XYTextAnnotation xytextannotation = null; Font font = new Font("SansSerif", 0, 9); xytextannotation = new XYTextAnnotation("3rd", 36.5D, 11.76D); xytextannotation.setFont(font); xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT); xyplot.addAnnotation(xytextannotation); xytextannotation = new XYTextAnnotation("5th", 36.5D, 12.039999999999999D); xytextannotation.setFont(font); xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT); xyplot.addAnnotation(xytextannotation); xytextannotation = new XYTextAnnotation("10th", 36.5D, 12.493D); xytextannotation.setFont(font); xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT); xyplot.addAnnotation(xytextannotation); xytextannotation = new XYTextAnnotation("25th", 36.5D, 13.313000000000001D); xytextannotation.setFont(font); xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT); xyplot.addAnnotation(xytextannotation); xytextannotation = new XYTextAnnotation("50th", 36.5D, 14.33D); xytextannotation.setFont(font); xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT); xyplot.addAnnotation(xytextannotation); xytextannotation = new XYTextAnnotation("75th", 36.5D, 15.478D); xytextannotation.setFont(font); xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT); xyplot.addAnnotation(xytextannotation); xytextannotation = new XYTextAnnotation("90th", 36.5D, 16.641999999999999D); xytextannotation.setFont(font); xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT); xyplot.addAnnotation(xytextannotation); xytextannotation = new XYTextAnnotation("95th", 36.5D, 17.408000000000001D); xytextannotation.setFont(font); xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT); xyplot.addAnnotation(xytextannotation); xytextannotation = new XYTextAnnotation("97th", 36.5D, 17.936D); xytextannotation.setFont(font); xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT); xyplot.addAnnotation(xytextannotation); return jfreechart; }
From source file:no.met.jtimeseries.chart.ChartPlotter.java
public static XYTextAnnotation createTextAnnotation(String label, double x, double y, TextAnchor textAnchor, Color color) {//w w w .ja v a2s . c o m final XYTextAnnotation textAnnotation = new XYTextAnnotation(label, x, y + 0.1d); textAnnotation.setTextAnchor(TextAnchor.BOTTOM_LEFT); textAnnotation.setPaint(color); return textAnnotation; }
From source file:com.bdb.weather.display.day.DayHumidityPane.java
@Override protected void addAnnotations(XYPlot plot, SummaryRecord summaryRecord) { plot.clearAnnotations();//from w w w .j ava2 s. c o m if (summaryRecord == null) return; LocalDateTime highTime = summaryRecord.getMaxOutdoorHumidityTime(); Humidity highHumidity = summaryRecord.getMaxOutdoorHumidity(); LocalDateTime lowTime = summaryRecord.getMinOutdoorHumidityTime(); Humidity lowHumidity = summaryRecord.getMinOutdoorHumidity(); if (highTime == null || highHumidity == null || lowTime == null || lowHumidity == null) return; String highAnnotation = highHumidity.toString() + Humidity.Unit.RELATIVE_HUMIDITY + " " + DisplayConstants.formatTime(highTime.toLocalTime()); String lowAnnotation = lowHumidity.toString() + Humidity.Unit.RELATIVE_HUMIDITY + " " + DisplayConstants.formatTime(lowTime.toLocalTime()); XYTextAnnotation a = new XYTextAnnotation(highAnnotation, TimeUtils.localDateTimeToEpochMillis(highTime), highHumidity.get()); a.setTextAnchor(TextAnchor.BASELINE_CENTER); plot.addAnnotation(a); a = new XYTextAnnotation(lowAnnotation, TimeUtils.localDateTimeToEpochMillis(lowTime), lowHumidity.get()); a.setTextAnchor(TextAnchor.TOP_CENTER); plot.addAnnotation(a); }
From source file:org.owasp.benchmark.score.report.ScatterTools.java
private void makeDataLabels(OverallResults or, XYPlot xyplot) { HashMap<Point2D, String> map = makePointList(or); for (Entry<Point2D, String> e : map.entrySet()) { if (e.getValue() != null) { Point2D p = e.getKey(); String label = sort(e.getValue()); XYTextAnnotation annotation = new XYTextAnnotation(label, p.getX(), p.getY()); annotation.setTextAnchor(p.getX() < 3 ? TextAnchor.TOP_LEFT : TextAnchor.TOP_CENTER); annotation.setBackgroundPaint(Color.white); // set color of average to black and everything else to blue if (averageLabel == label.toCharArray()[0]) { annotation.setPaint(Color.magenta); } else { annotation.setPaint(Color.blue); }//from w w w . j av a2 s .com annotation.setFont(theme.getRegularFont()); xyplot.addAnnotation(annotation); } } }
From source file:com.bdb.weather.display.day.DayPressurePane.java
@Override protected void addAnnotations(XYPlot plot, SummaryRecord summaryRecord) { plot.getRenderer(0).removeAnnotations(); plot.getRenderer(1).removeAnnotations(); if (summaryRecord == null) return;/*ww w .j a v a 2 s . com*/ LocalDateTime maxTime = summaryRecord.getMaxBaroPressureTime(); Pressure maxBaroPressure = summaryRecord.getMaxBaroPressure(); LocalDateTime minTime = summaryRecord.getMinBaroPressureTime(); Pressure minBaroPressure = summaryRecord.getMinBaroPressure(); // // Barometric pressure // String highAnnotation = maxBaroPressure.toString() + Pressure.getDefaultUnit() + " " + DisplayConstants.formatTime(maxTime.toLocalTime()); String lowAnnotation = minBaroPressure.toString() + Pressure.getDefaultUnit() + " " + DisplayConstants.formatTime(minTime.toLocalTime()); XYTextAnnotation a = new XYTextAnnotation(highAnnotation, (double) TimeUtils.localDateTimeToEpochMillis(maxTime), maxBaroPressure.get()); a.setTextAnchor(TextAnchor.BASELINE_CENTER); plot.getRenderer(0).addAnnotation(a); TextAnchor anchor = TextAnchor.TOP_CENTER; if (minTime.getHour() <= 2) anchor = TextAnchor.TOP_LEFT; else if (minTime.getHour() >= 22) anchor = TextAnchor.TOP_RIGHT; a = new XYTextAnnotation(lowAnnotation, (double) TimeUtils.localDateTimeToEpochMillis(minTime), minBaroPressure.get()); a.setTextAnchor(anchor); plot.getRenderer(0).addAnnotation(a); SolarRadiation maxSolarRadiation = summaryRecord.getMaxSolarRadiation(); maxTime = summaryRecord.getMaxSolarRadiationTime(); if (maxSolarRadiation != null) { highAnnotation = maxSolarRadiation.toString() + SolarRadiation.Unit.WATTS_PER_METER_SQUARED + " " + DisplayConstants.formatTime(maxTime.toLocalTime()); a = new XYTextAnnotation(highAnnotation, (double) TimeUtils.localDateTimeToEpochMillis(maxTime), maxSolarRadiation.get()); a.setTextAnchor(TextAnchor.BASELINE_CENTER); plot.getRenderer(1).addAnnotation(a); } }
From source file:org.owasp.benchmark.score.report.ScatterTools.java
private void makeLegend(OverallResults or, double x, double y, XYSeriesCollection dataset, XYPlot xyplot) { char ch = ScatterHome.INITIAL_LABEL; int i = 0;// w w w . j a va2 s. c om int toolCount = 0; double totalScore = 0; for (OverallResult r : or.getResults()) { toolCount++; // Special hack to make it line up better if the letter is an 'I' or 'i' String label = (ch == 'I' || ch == 'i' ? ch + ": " : "" + ch + ": "); double score = 100 * (r.truePositiveRate - r.falsePositiveRate); String msg = "\u25A0 " + label + r.category + " (" + Math.round(score) + "%)"; totalScore += score; XYTextAnnotation stroketext = new XYTextAnnotation(msg, x, y + i * -3.3); stroketext.setTextAnchor(TextAnchor.CENTER_LEFT); stroketext.setBackgroundPaint(Color.white); stroketext.setPaint(Color.blue); stroketext.setFont(theme.getRegularFont()); xyplot.addAnnotation(stroketext); i++; // Weak hack if there are more than 26 tools scored. This will only get us to 52. if (ch == 'Z') ch = 'a'; else ch++; } if (toolCount > 1) { double averageScore = totalScore / toolCount; XYTextAnnotation stroketext = new XYTextAnnotation( "\u25A0 " + ch + ": Average Score for this Tool" + " (" + Math.round(averageScore) + "%)", x, y + i * -3.3); stroketext.setTextAnchor(TextAnchor.CENTER_LEFT); stroketext.setBackgroundPaint(Color.white); stroketext.setPaint(Color.magenta); stroketext.setFont(theme.getRegularFont()); xyplot.addAnnotation(stroketext); Point2D averagePoint = new Point2D.Double(afpr * 100, atpr * 100); makePoint(xyplot, averagePoint, 3, Color.magenta); } }
From source file:com.bdb.weather.display.day.DayWindPane.java
@Override protected void addAnnotations(XYPlot plot, SummaryRecord summaryRecord) { plot.clearAnnotations();/*ww w . j a v a2s .c o m*/ if (summaryRecord == null) return; LocalDateTime maxSpeedTime = summaryRecord.getMaxWindSpeedTime(); if (maxSpeedTime != null) { double maxSpeed = summaryRecord.getMaxWindSpeed().get(); String maxSpeedAnnotation = Speed.getDefaultFormatter().format(maxSpeed) + Speed.getDefaultUnit() + " " + DisplayConstants.formatTime(maxSpeedTime.toLocalTime()); XYTextAnnotation a = new XYTextAnnotation(maxSpeedAnnotation, (double) TimeUtils.localDateTimeToEpochMillis(maxSpeedTime), maxSpeed); a.setTextAnchor(TextAnchor.BASELINE_CENTER); plot.addAnnotation(a); } }
From source file:org.owasp.benchmark.score.report.ScatterTools.java
private JFreeChart display(String title, int height, OverallResults or) { JFrame f = new JFrame(title); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series = new XYSeries("Scores"); int totalTools = 0; double totalToolTPR = 0; double totalToolFPR = 0; for (OverallResult r : or.getResults()) { series.add(r.falsePositiveRate * 100, r.truePositiveRate * 100); totalTools++;/*from ww w. j av a2s .c o m*/ totalToolTPR += r.truePositiveRate; totalToolFPR += r.falsePositiveRate; } atpr = totalToolTPR / totalTools; afpr = totalToolFPR / totalTools; if (or.getResults().size() > 1) { series.add(afpr * 100, atpr * 100); } dataset.addSeries(series); chart = ChartFactory.createScatterPlot(title, "False Positive Rate", "True Positive Rate", dataset, PlotOrientation.VERTICAL, true, true, false); theme.apply(chart); XYPlot xyplot = chart.getXYPlot(); initializePlot(xyplot); makeDataLabels(or, xyplot); makeLegend(or, 103, 93, dataset, xyplot); XYTextAnnotation time = new XYTextAnnotation("Tool run time: " + or.getTime(), 12, -5.6); time.setTextAnchor(TextAnchor.TOP_LEFT); time.setFont(theme.getRegularFont()); time.setPaint(Color.red); xyplot.addAnnotation(time); ChartPanel cp = new ChartPanel(chart, height, height, 400, 400, 1200, 1200, false, false, false, false, false, false); f.add(cp); f.pack(); f.setLocationRelativeTo(null); // f.setVisible(true); return chart; }
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);/*from w w w. j av a 2 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.owasp.benchmark.score.report.Scatter.java
private void makeLegend(OverallResults or, int x, int y, XYSeriesCollection dataset, XYPlot xyplot) { char ch = 'A'; int i = 0;// w ww . ja v a 2s. c om for (OverallResult r : or.getResults()) { String label = (ch == 'I' ? ch + ": " : "" + ch + ": "); int score = (int) (100 * (r.tpr - r.fpr)); String msg = "\u25A0 " + label + r.category + " (" + score + "%)"; XYTextAnnotation stroketext = new XYTextAnnotation(msg, x, y + i * -3.3); stroketext.setTextAnchor(TextAnchor.CENTER_LEFT); stroketext.setBackgroundPaint(Color.white); stroketext.setPaint(Color.blue); stroketext.setFont(theme.getRegularFont()); xyplot.addAnnotation(stroketext); i++; ch++; } }