List of usage examples for org.jfree.chart.annotations XYTextAnnotation XYTextAnnotation
public XYTextAnnotation(String text, double x, double y)
From source file:no.met.jtimeseries.chart.ErrorPlot.java
public static XYPlot getMarinogramErrorPlot() { XYItemRenderer renderer = new StandardXYItemRenderer(); NumberAxis rangeAxis = new NumberAxis(); XYPlot plot = new XYPlot(null, null, rangeAxis, renderer); XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 0.5, 0.5); annotation.setFont(new Font("SansSerif", Font.PLAIN, 9)); plot.addAnnotation(annotation);//from w w w . j a va 2 s .c o m return plot; }
From source file:com.orange.atk.results.logger.log.Action.java
/** * Set Annotation properties used in Analysis Tool (keypress,log,screenshot...) * For each action a marker and an Annotation is related * @param Xvalue StartTime of Marker Action * @param Yvalue Position where to display the comment 1 for the top 0 for the bottom * @param color Color of Marker// w ww . j a v a 2s .com */ public void setAnnotation(double Xvalue, Paint color) { if (szActionName != null) { annotation = new XYTextAnnotation(szActionName, Xvalue, 0.05); annotation.setFont(new Font("SansSerif", Font.PLAIN, 12)); annotation.setRotationAngle(3 * Math.PI / 2); annotation.setRotationAnchor(TextAnchor.BOTTOM_LEFT); annotation.setTextAnchor(TextAnchor.BOTTOM_LEFT); annotation.setToolTipText(szActionName); annotation.setPaint(color); } }
From source file:statUtil.TurnMovementPlot.java
public TurnMovementPlot(String title) throws IOException { super(title); Data data = CSVData.getCSVData(TURN_CSV_LOG); JFreeChart chart = ChartFactory.createXYLineChart(title, "X", "Y", XYDatasetGenerator.generateXYDataset(data.csvData)); final XYPlot xyPlot = chart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesStroke(0, new BasicStroke(3f)); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, false); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShapesVisible(1, true); Shape cross = ShapeUtilities.createDiagonalCross(2f, 0.5f); renderer.setSeriesShape(1, cross);/* w ww . j a v a 2 s . c o m*/ xyPlot.setRenderer(renderer); xyPlot.setQuadrantOrigin(new Point(0, 0)); int i = 0; for (Double[] csvRow : data.csvData) { if (i % 20 == 1) { final XYTextAnnotation annotation = new XYTextAnnotation(Double.toString(csvRow[3]), csvRow[0], csvRow[1]); annotation.setFont(new Font("SansSerif", Font.PLAIN, 10)); xyPlot.addAnnotation(annotation); } i++; } int width = (int) Math.round(data.maxX - data.minX) + 50; int height = (int) Math.round(data.maxY - data.minY) + 50; ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(width, height)); setContentPane(chartPanel); File XYChart = new File(FILE_PATH + "\\TurnMovementPlot.png"); ChartUtilities.saveChartAsPNG(XYChart, chart, width, height); }
From source file:com.bdb.weather.display.day.DayHumidityPane.java
@Override protected void addAnnotations(XYPlot plot, SummaryRecord summaryRecord) { plot.clearAnnotations();//from ww w .jav a 2 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 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++;// www . j av a 2 s .co 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:com.che.software.testato.util.jfreechart.LineChartGraphistUtil.java
/** * Colorized and transforms a given JFreeChart. * /* w w w .j ava 2 s. c o m*/ * @author Clement HELIOU (clement.heliou@che-software.com). * @param lineChart the given chart. * @param maxAbscissaValue the max abscissa value of the chart. * @param xValues the x axis values list. * @param yValues the y axis values list. * @param xExcludedValues the x axis excluded values. * @param yExcludedValues the y axis excluded values. * @return the transformed chart. * @since August, 2011. */ public static JFreeChart getColorizedChartFromChart(JFreeChart lineChart, double maxAbscissaValue, List<MatrixResult> xValues, List<MatrixResult> yValues, List<MatrixResult> xExcludedValues, List<MatrixResult> yExcludedValues) { LOGGER.debug("getColorizedChartFromChart()."); lineChart.setBackgroundPaint(Color.WHITE); XYPlot plot = (XYPlot) lineChart.getPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesStroke(2, new BasicStroke(2)); renderer.setSeriesStroke(3, new BasicStroke(2)); renderer.setSeriesShapesVisible(2, false); renderer.setSeriesShapesVisible(3, false); renderer.setSeriesPaint(0, ColorUtil.getHSBColor(ColorUtil.BLUE_COLOR[0], ColorUtil.BLUE_COLOR[1], ColorUtil.BLUE_COLOR[2])); renderer.setSeriesPaint(1, ColorUtil.getHSBColor(ColorUtil.ORANGE_COLOR[0], ColorUtil.ORANGE_COLOR[1], ColorUtil.ORANGE_COLOR[2])); renderer.setSeriesPaint(2, ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1], ColorUtil.DARK_BLUE_COLOR[2])); renderer.setSeriesPaint(3, ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1], ColorUtil.DARK_BLUE_COLOR[2])); plot.setRenderer(renderer); XYTextAnnotation low = new XYTextAnnotation( LocaleUtil.getResourceBundleStringByName(LocaleUtil.AREA_LOW_NAME), (0.5 * maxAbscissaValue) - 1, maxAbscissaValue + 1), medium = new XYTextAnnotation(LocaleUtil.getResourceBundleStringByName(LocaleUtil.AREA_MEDIUM_NAME), (1.5 * maxAbscissaValue) - 2, maxAbscissaValue + 1), high = new XYTextAnnotation(LocaleUtil.getResourceBundleStringByName(LocaleUtil.AREA_HIGH_NAME), 1.5 * maxAbscissaValue, maxAbscissaValue - 2); low.setFont(ColorUtil.TITLE_FONT); medium.setFont(ColorUtil.TITLE_FONT); high.setFont(ColorUtil.TITLE_FONT); low.setPaint(ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1], ColorUtil.DARK_BLUE_COLOR[2])); medium.setPaint(ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1], ColorUtil.DARK_BLUE_COLOR[2])); high.setPaint(ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1], ColorUtil.DARK_BLUE_COLOR[2])); plot.addAnnotation(low); plot.addAnnotation(medium); plot.addAnnotation(high); for (int i = 0; i < xValues.size(); i++) { XYTextAnnotation itemLabel = new XYTextAnnotation(xValues.get(i).getScriptLabel(), (yValues.get(i).getPercentage() * 100), (xValues.get(i).getPercentage() * 100) + 0.5); itemLabel.setFont(ColorUtil.DEFAULT_FONT); itemLabel.setPaint(ColorUtil.getHSBColor(ColorUtil.BLUE_COLOR[0], ColorUtil.BLUE_COLOR[1], ColorUtil.BLUE_COLOR[2])); plot.addAnnotation(itemLabel); } if (null != xExcludedValues) { for (int j = 0; j < xExcludedValues.size(); j++) { XYTextAnnotation itemLabel = new XYTextAnnotation(xExcludedValues.get(j).getScriptLabel(), (yExcludedValues.get(j).getPercentage() * 100), (xExcludedValues.get(j).getPercentage() * 100) + 0.5); itemLabel.setFont(ColorUtil.DEFAULT_FONT); itemLabel.setPaint(ColorUtil.getHSBColor(ColorUtil.ORANGE_COLOR[0], ColorUtil.ORANGE_COLOR[1], ColorUtil.ORANGE_COLOR[2])); plot.addAnnotation(itemLabel); } } return lineChart; }
From source file:org.jfree.chart.demo.CombinedXYPlotDemo1.java
/** * Creates a combined chart./*from w ww . j a v a2 s.co m*/ * * @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.jfree.chart.demo.Graphic.java
public ChartPanel get_ChartPanel(int width, int height) { chr = new ChartPanel(chart); chr.setBackground(Color.blue); chr.setBounds(5, 5, width - 5, height - 10); chr.setVisible(true);/*from ww w.ja v a2 s. c o m*/ chr.setMouseWheelEnabled(true); chr.addChartMouseListener(new ChartMouseListener() { public void chartMouseMoved(ChartMouseEvent chartmouseevent) { } public void chartMouseClicked(ChartMouseEvent chartmouseevent) { SwingUtilities.invokeLater(new Runnable() { public void run() { XYPlot xyplot = (XYPlot) chr.getChart().getPlot(); xyplot.clearAnnotations(); double x, y; x = new BigDecimal(xyplot.getDomainCrosshairValue()).setScale(3, RoundingMode.UP) .doubleValue(); y = new BigDecimal(xyplot.getRangeCrosshairValue()).setScale(3, RoundingMode.UP) .doubleValue(); XYTextAnnotation annotation = new XYTextAnnotation("(" + x + ", " + y + ")", new BigDecimal(x).setScale(3, RoundingMode.UP).doubleValue(), y); annotation.setFont(new Font("serif", Font.BOLD, 15)); annotation.setTextAnchor(TextAnchor.BOTTOM_CENTER); xyplot.addAnnotation(annotation); } }); } }); return chr; }
From source file:org.fhcrc.cpl.viewer.ms2.gui.MS2ScanViewer.java
protected void buildChart() { if (scanInViewer == null) return;// w w w . j a va2 s . com if (chartInViewer != null) { remove(chartInViewer); } float[][] spectrum = scanInViewer.getSpectrum(); float[] mzValues = new float[spectrum[0].length]; float[] intensityValues = new float[spectrum[0].length]; for (int i = 0; i < mzValues.length; i++) { mzValues[i] = spectrum[0][i]; intensityValues[i] = spectrum[1][i]; } chartInViewer = new PanelWithPeakChart(mzValues, intensityValues, "ms2scan"); //add labels for highest peaks if (numHighestPeaksToLabel > 0) { XYPlot xyPlot = chartInViewer.getChart().getXYPlot(); List<Pair<Float, Float>> peaksAsPairs = new ArrayList<Pair<Float, Float>>(); for (int i = 0; i < mzValues.length; i++) peaksAsPairs.add(new Pair<Float, Float>(mzValues[i], intensityValues[i])); Collections.sort(peaksAsPairs, new Comparator<Pair<Float, Float>>() { @Override public int compare(Pair<Float, Float> pair1, Pair<Float, Float> pair2) { float diff = pair1.second - pair2.second; if (diff > 0) return -1; if (diff < 0) return 1; return 0; } }); for (int i = 0; i < numHighestPeaksToLabel; i++) { Pair<Float, Float> pair = peaksAsPairs.get(i); xyPlot.addAnnotation( new XYTextAnnotation("" + Rounder.round(pair.first, 3), pair.first, pair.second)); } } add(chartInViewer); updateUI(); }
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;//from w w w .ja va 2 s . co m 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); } }