List of usage examples for org.jfree.chart.plot XYPlot addAnnotation
public void addAnnotation(XYAnnotation annotation)
From source file:org.jfree.chart.demo.PlotOrientationDemo.java
/** * Creates a new demo instance.//from ww w . j av a 2s .c o m * * @param title the frame title. */ public PlotOrientationDemo(String title) { super(title); JPanel panel = new JPanel(new GridLayout(2, 4)); for (int i = 0; i < CHART_COUNT; i++) { this.datasets[i] = createDataset(i); this.charts[i] = createChart(i, this.datasets[i]); XYPlot plot = this.charts[i].getXYPlot(); XYShapeAnnotation a1 = new XYShapeAnnotation(new Rectangle2D.Double(1.0, 2.0, 2.0, 3.0), new BasicStroke(1.0f), Color.blue); XYLineAnnotation a2 = new XYLineAnnotation(0.0, -5.0, 10.0, -5.0); XYImageAnnotation a3 = new XYImageAnnotation(5.0, 2.0, JFreeChart.INFO.getLogo()); plot.addAnnotation(a1); plot.addAnnotation(a2); plot.addAnnotation(a3); plot.setQuadrantPaint(0, new Color(230, 230, 255)); plot.setQuadrantPaint(1, new Color(230, 255, 230)); plot.setQuadrantPaint(2, new Color(255, 230, 230)); plot.setQuadrantPaint(3, new Color(255, 230, 255)); this.panels[i] = new ChartPanel(this.charts[i]); } this.charts[1].getXYPlot().getDomainAxis().setInverted(true); this.charts[2].getXYPlot().getRangeAxis().setInverted(true); this.charts[3].getXYPlot().getDomainAxis().setInverted(true); this.charts[3].getXYPlot().getRangeAxis().setInverted(true); this.charts[5].getXYPlot().getDomainAxis().setInverted(true); this.charts[6].getXYPlot().getRangeAxis().setInverted(true); this.charts[4].getXYPlot().getDomainAxis().setInverted(true); this.charts[4].getXYPlot().getRangeAxis().setInverted(true); this.charts[4].getXYPlot().setOrientation(PlotOrientation.HORIZONTAL); this.charts[5].getXYPlot().setOrientation(PlotOrientation.HORIZONTAL); this.charts[6].getXYPlot().setOrientation(PlotOrientation.HORIZONTAL); this.charts[7].getXYPlot().setOrientation(PlotOrientation.HORIZONTAL); panel.add(this.panels[0]); panel.add(this.panels[1]); panel.add(this.panels[4]); panel.add(this.panels[5]); panel.add(this.panels[2]); panel.add(this.panels[3]); panel.add(this.panels[6]); panel.add(this.panels[7]); panel.setPreferredSize(new Dimension(800, 600)); setContentPane(panel); }
From source file:net.sourceforge.processdash.ui.web.reports.snippets.EstErrorScatterChart.java
@Override public JFreeChart createChart() { JFreeChart chart = super.createChart(); // set minimum/maximum bounds on the two axes XYPlot xyPlot = chart.getXYPlot(); double cutoff = getPercentParam("cut", 100, 200, 5000); xyPlot.setDomainAxis(truncAxis(xyPlot.getDomainAxis(), cutoff)); xyPlot.setRangeAxis(truncAxis(xyPlot.getRangeAxis(), cutoff)); xyPlot.setRenderer(new TruncatedItemRenderer(xyPlot.getRenderer())); // add a box illustrating the target range if (data.numRows() > 0) { double box = getPercentParam("pct", 0, 50, 100); xyPlot.addAnnotation(new XYBoxAnnotation(-box, -box, box, box)); xyPlot.addAnnotation(new XYLineAnnotation(-box, 0, box, 0)); xyPlot.addAnnotation(new XYLineAnnotation(0, -box, 0, box)); }//from w ww . j a v a 2 s.c om return chart; }
From source file:net.sf.statcvs.output.xml.chart.LocChart.java
private void makeTagAnnotations() { XYPlot xyplot = getChart().getXYPlot(); Iterator tagIt = tagMap.keySet().iterator(); while (tagIt.hasNext()) { String tag = (String) tagIt.next(); Date date = (Date) tagMap.get(tag); double x = date.getTime(); double y1 = xyplot.getRangeAxis().getMinimumAxisValue(); double y2 = xyplot.getRangeAxis().getMaximumAxisValue(); xyplot.addAnnotation(new TagAnnotation(tag, x, y1, y2)); }/* ww w. j a v a 2 s .com*/ }
From source file:adapters.XYChartAdapter.java
/** * Draws a vertical line on the chart at <SPAN CLASS="MATH"><I>x</I></SPAN>-coordinate <TT>x</TT>. * <TT>name</TT> is written near the line at <SPAN CLASS="MATH"><I>y</I></SPAN> position <TT>yfrac</TT> * (a fraction of the <SPAN CLASS="MATH"><I>y</I></SPAN>-size of the chart, 0 is the bottom, 1 is the top); * if <TT>right</TT> is <TT>true</TT>, <TT>name</TT> is written on the right * of the line, else on the left./*www . j a va2 s . c o m*/ * * @param x <SPAN CLASS="MATH"><I>x</I></SPAN>-coordinate of the line * * @param name description of the line * * @param yfrac <SPAN CLASS="MATH"><I>y</I></SPAN>-position of name * * @param right <SPAN CLASS="MATH"><I>x</I></SPAN>-position of name * */ public void drawVerticalLine(double x, String name, double yfrac, boolean right) { double ybottom = YAxis.getAxis().getLowerBound(); final Object o = this; if (this instanceof HistogramChartAdapter) ybottom = 0; double ytop = YAxis.getAxis().getUpperBound(); XYLineAnnotation line = new XYLineAnnotation(x, ybottom, x, ytop); XYTextAnnotation text = new XYTextAnnotation(name, x, ytop * yfrac); if (!right) text.setTextAnchor(TextAnchor.HALF_ASCENT_RIGHT); else text.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT); XYPlot plot = getJFreeChart().getXYPlot(); plot.addAnnotation(line); plot.addAnnotation(text); }
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++;/* ww w. jav a 2s. 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:it.cnr.istc.iloc.gui.TimelinesChart.java
@Override public void currentNode(Solver.Node n) { final CombinedDomainXYPlot combined_plot = new CombinedDomainXYPlot(new DateAxis("Time")); combined_plot.setGap(3.0);//from w ww . j a va 2s. c o m combined_plot.setOrientation(PlotOrientation.VERTICAL); Set<Type> c_types = new HashSet<>(); LinkedList<Type> queue = new LinkedList<>(); queue.addAll(solver.getTypes()); while (!queue.isEmpty()) { Type c_type = queue.pollFirst(); if (!c_types.contains(c_type)) { c_types.add(c_type); queue.addAll(c_type.getTypes()); } } for (Type type : c_types) { if (visualizers.containsKey(type.getClass())) { for (XYPlot plot : visualizers.get(type.getClass()).getPlots(type)) { TextTitle title = new TextTitle(type.name, new Font("SansSerif", Font.PLAIN, 11), Color.BLACK, RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.BOTTOM, new RectangleInsets(4, 4, 4, 4)); XYTitleAnnotation titleAnn = new XYTitleAnnotation(0.01, 1, title, RectangleAnchor.TOP_LEFT); plot.addAnnotation(titleAnn); combined_plot.add(plot, 1); } } } setChart(new JFreeChart("", new Font("SansSerif", Font.BOLD, 14), combined_plot, false)); setBorder(BorderFactory.createEtchedBorder()); }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.DoseResponseController.java
/** * Create a dose-response chart containing experimental data, simulated data * and an annotated R value.//from w w w .ja v a 2 s .c o m * * @param dataToPlot The experimental data on which the fit was performed * @param analysisGroup The analysis group * @param normalized Whether the responses are normalized * @return */ public JFreeChart createDoseResponseChart(List<DoseResponsePair> dataToPlot, DoseResponseAnalysisGroup analysisGroup, boolean normalized) { // setup scatter data of experimental concentrations/slopes, renderer and axis XYSeriesCollection experimentalData = new XYSeriesCollection(); XYSeries scatterXYSeries = JFreeChartUtils.generateXYSeries(AnalysisUtils.generateXValues(dataToPlot), AnalysisUtils.generateYValues(dataToPlot)); scatterXYSeries.setKey("Experimental data"); experimentalData.addSeries(scatterXYSeries); // compute how far the simulated data and axes should range: from the lowest and highest dose continue half of the range between these two List<Double> extremes = new ArrayList<>(); Double range = Math.abs(scatterXYSeries.getMaxX() - scatterXYSeries.getMinX()); extremes.add(scatterXYSeries.getMinX() - (range / 2)); extremes.add(scatterXYSeries.getMaxX() + (range / 2)); // Create the simulated line data, renderer, and axis XYSeriesCollection fitting = new XYSeriesCollection(); // create xy series of simulated data from the parameters from the fitting SigmoidFittingResultsHolder resultsHolder = analysisGroup.getDoseResponseAnalysisResults() .getFittingResults(normalized); XYSeries fittingData = simulateData(resultsHolder, extremes); fittingData.setKey("Fitting"); fitting.addSeries(fittingData); XYPlot plot = JFreeChartUtils.setupDoseResponseDatasets(experimentalData, fitting, getPlotAxesNames(normalized), extremes); // show the r squared value, put the value at a certain place between the min and max dose double xPlace = extremes.get(1) - range; double yPlace = scatterXYSeries.getMinY() + ((scatterXYSeries.getMaxY() - scatterXYSeries.getMinY()) / 4); plot.addAnnotation(new XYTextAnnotation( "R2=" + AnalysisUtils.roundThreeDecimals(AnalysisUtils.computeRSquared(dataToPlot, resultsHolder)), xPlace, yPlace)); // Create the chart with the plot and no legend JFreeChart chart = new JFreeChart("Title", JFreeChart.DEFAULT_TITLE_FONT, plot, false); String title = ""; if (normalized) { title = "Normalized fitting"; } else { title = "Initial fitting"; } JFreeChartUtils.setupDoseResponseChart(chart, title); return chart; }
From source file:org.openscience.cdk.applications.taverna.basicutilities.ChartTool.java
/** * Creates a residue plot.//w w w. j a v a2 s . c om * * @param yValues * @param header * @param xAxis * @param yAxis * @param seriesNames * @return */ public JFreeChart createResiduePlot(List<Double[]> yValues, String header, String xAxis, String yAxis, List<String> seriesNames) { LinkedList<XYLineAnnotation> lines = new LinkedList<XYLineAnnotation>(); DefaultXYDataset xyDataSet = new DefaultXYDataset(); for (int j = 0; j < yValues.size(); j++) { XYSeries series = new XYSeries(seriesNames.get(j)); for (int i = 0; i < yValues.get(j).length; i++) { series.add(i + 1, yValues.get(j)[i]); float dash[] = { 10.0f }; BasicStroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f); XYLineAnnotation annotation = new XYLineAnnotation(i + 1, 0, i + 1, yValues.get(j)[i], stroke, Color.BLUE); lines.add(annotation); } xyDataSet.addSeries(seriesNames.get(j), series.toArray()); } JFreeChart chart = ChartFactory.createScatterPlot(header, xAxis, yAxis, xyDataSet, PlotOrientation.VERTICAL, true, false, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setNoDataMessage("NO DATA"); plot.setDomainZeroBaselineVisible(true); plot.setRangeZeroBaselineVisible(true); for (int i = 0; i < lines.size(); i++) { plot.addAnnotation(lines.get(i)); } XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesOutlinePaint(0, Color.black); renderer.setUseOutlinePaint(true); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRangeIncludesZero(false); domainAxis.setTickMarkInsideLength(2.0f); domainAxis.setTickMarkOutsideLength(0.0f); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setTickMarkInsideLength(2.0f); rangeAxis.setTickMarkOutsideLength(0.0f); return chart; }
From source file:org.openscience.cdk.applications.taverna.basicutilities.ChartTool.java
/** * Creates a scatter plot.//from ww w. j ava 2s. c o m * * @param dataset * @param header * @param xAxis * @param yAxis * @return */ public JFreeChart createScatterPlot(XYDataset dataset, String header, String xAxis, String yAxis) { JFreeChart chart = ChartFactory.createScatterPlot(header, xAxis, yAxis, dataset, PlotOrientation.VERTICAL, true, false, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setNoDataMessage("NO DATA"); plot.setDomainZeroBaselineVisible(true); plot.setRangeZeroBaselineVisible(true); XYLineAnnotation annotation = new XYLineAnnotation(-1000000, -1000000, 1000000, 1000000); plot.addAnnotation(annotation); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesOutlinePaint(0, Color.black); renderer.setUseOutlinePaint(true); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRangeIncludesZero(false); domainAxis.setTickMarkInsideLength(2.0f); domainAxis.setTickMarkOutsideLength(0.0f); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setTickMarkInsideLength(2.0f); rangeAxis.setTickMarkOutsideLength(0.0f); return chart; }
From source file:my.electrochem.ElectrochemUI.java
private void createLineAnn(XYPlot plot, double a1, double b1, double a2, double b2) { if (!(a1 == 0.0)) { XYLineAnnotation ann1 = new XYLineAnnotation(a1, b1, a2, b2); plot.addAnnotation(ann1); x1 = -423.0;//from w w w . j a v a 2 s .c o m } }