List of usage examples for org.jfree.chart.plot XYPlot addAnnotation
public void addAnnotation(XYAnnotation annotation)
From source file:AsymptoticFreedom.GraphViewPanel.java
public JFreeChart getResultChart() { // XY ?/*ww w . j a va 2 s .c o m*/ int quark_size = ViewPanel.quark_list.size(); if (quark_size < 2) return new JFreeChart(new XYPlot()); // XY Dataset XYSeriesCollection data = new XYSeriesCollection(); //System.out.println(series.get(0).getY(30)); for (XYSeries s : series) { data.addSeries(s); } final JFreeChart chart = ChartFactory.createXYLineChart("Potential", "Distance", "Potential", data, PlotOrientation.VERTICAL, true, true, false); chart.setTitle("Potential of quarks"); // ? XYPlot plot = (XYPlot) chart.getPlot(); //plot.addRangeMarker(new ValueMarker(15,Color.RED,new BasicStroke(2.0f))); for (int i = 0; i < quark_size; i++) { for (int j = i + 1; j < quark_size; j++) { Quark quark1 = ViewPanel.quark_list.get(i); Quark quark2 = ViewPanel.quark_list.get(j); double distance = quark1.pos.distance(quark2.pos); double value = quark1.calculatePotential(quark2); String anno_title = String.format("V_ %c-%c", quark1.color.charAt(0), quark2.color.charAt(0)); //System.out.println(anno_title); XYPointerAnnotation pointer = new XYPointerAnnotation(anno_title, distance, value, 3.0 * Math.PI / 4.0); plot.addAnnotation(pointer); } } plot.getRangeAxis().setRange(-500, 4000); return chart; }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.explore.EnclosingBallController.java
public void plotXYBalls(TrackDataHolder trackDataHolder) { int selectedIndexRadius = exploreTrackController.getExploreTrackPanel().getEnclosingBallRadiusCombobox() .getSelectedIndex();/*from ww w . j av a 2 s . com*/ List<List<EnclosingBall>> enclosingBallsList = trackDataHolder.getStepCentricDataHolder() .getxYEnclosingBalls(); List<EnclosingBall> enclosingBalls = enclosingBallsList.get(selectedIndexRadius); // get the coordinates matrix Double[][] coordinatesMatrix = trackDataHolder.getStepCentricDataHolder().getCoordinatesMatrix(); XYSeries xYSeries = JFreeChartUtils.generateXYSeries(coordinatesMatrix); String seriesKey = "track " + trackDataHolder.getTrack().getTrackNumber() + ", well " + trackDataHolder.getTrack().getWellHasImagingType().getWell(); xYSeries.setKey(seriesKey); XYSeriesCollection ySeriesCollection = new XYSeriesCollection(xYSeries); JFreeChart chart = ChartFactory.createXYLineChart(seriesKey + " - enclosing balls", "x (m)", "y (m)", ySeriesCollection, PlotOrientation.VERTICAL, false, true, false); XYPlot xyPlot = chart.getXYPlot(); JFreeChartUtils.setupXYPlot(xyPlot); JFreeChartUtils.setupSingleTrackPlot(chart, exploreTrackController.getExploreTrackPanel().getTracksList().getSelectedIndex(), true); XYSeriesCollection dataset = (XYSeriesCollection) xyPlot.getDataset(0); double minY = dataset.getSeries(0).getMinY(); double maxY = dataset.getSeries(0).getMaxY(); xyPlot.getRangeAxis().setRange(minY - 10, maxY + 10); xYBallsChartPanel.setChart(chart); enclosingBalls.stream().forEach((ball) -> { xyPlot.addAnnotation(new XYShapeAnnotation(ball.getShape(), JFreeChartUtils.getDashedLine(), GuiUtils.getDefaultColor())); }); }
From source file:org.owasp.benchmark.score.report.Scatter.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); annotation.setPaint(Color.blue); annotation.setFont(theme.getRegularFont()); xyplot.addAnnotation(annotation); }/*from w w w .j av a 2 s.co m*/ } }
From source file:org.owasp.benchmark.score.report.ScatterHome.java
private JFreeChart display(String title, int height, Set<Report> toolResults) { JFrame f = new JFrame(title); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //averages//from w w w .j a va 2 s.c o m ArrayList<Double> averageCommercialFalseRates = new ArrayList<Double>(); ArrayList<Double> averageCommercialTrueRates = new ArrayList<Double>(); XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series = new XYSeries("Scores"); for (Report toolReport : toolResults) { if (!toolReport.isCommercial()) { OverallResults overallResults = toolReport.getOverallResults(); series.add(overallResults.getFalsePositiveRate() * 100, overallResults.getTruePositiveRate() * 100); if (toolReport.isCommercial()) { averageCommercialFalseRates.add(overallResults.getFalsePositiveRate()); averageCommercialTrueRates.add(overallResults.getTruePositiveRate()); } } } int commercialToolCount = 0; for (Report toolReport : toolResults) { if (toolReport.isCommercial()) { commercialToolCount++; OverallResults overallResults = toolReport.getOverallResults(); if (!BenchmarkScore.showAveOnlyMode) { series.add(overallResults.getFalsePositiveRate() * 100, overallResults.getTruePositiveRate() * 100); } if (toolReport.isCommercial()) { averageCommercialFalseRates.add(overallResults.getFalsePositiveRate()); averageCommercialTrueRates.add(overallResults.getTruePositiveRate()); } } } for (double d : averageCommercialFalseRates) { afr += d; } afr = afr / averageCommercialFalseRates.size(); for (double d : averageCommercialTrueRates) { atr += d; } atr = atr / averageCommercialTrueRates.size(); if (commercialToolCount > 1 || (BenchmarkScore.showAveOnlyMode && commercialToolCount == 1)) { series.add(afr * 100, atr * 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(toolResults, xyplot); makeLegend(toolResults, 103, 100.5, dataset, xyplot); for (XYDataItem item : (List<XYDataItem>) series.getItems()) { double x = item.getX().doubleValue(); double y = item.getY().doubleValue(); double z = (x + y) / 2; XYLineAnnotation score = new XYLineAnnotation(x, y, z, z, dashed, Color.blue); xyplot.addAnnotation(score); } 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.jfree.chart.demo.CombinedXYPlotDemo4.java
/** * Creates a combined chart.//from ww w . j a v a2 s . c o 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); // 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.owasp.benchmark.score.report.ScatterScores.java
private void makeDataLabels(List<Report> toolResults, XYPlot xyplot) { HashMap<Point2D, String> map = makePointList(toolResults); 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); annotation.setPaint(Color.blue); annotation.setFont(theme.getRegularFont()); xyplot.addAnnotation(annotation); }/* w ww . j av a 2 s.c o m*/ } }
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 w w w. j a v a 2 s.co 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: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);//from ww w . j a va2 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:org.owasp.benchmark.score.report.ScatterVulns.java
private JFreeChart display(String title, int height, String category, Set<Report> toolResults) { JFrame f = new JFrame(title); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // averages// w ww.j av a 2 s.co m ArrayList<Double> averageFalseRates = new ArrayList<Double>(); ArrayList<Double> averageTrueRates = new ArrayList<Double>(); int commercialToolCount = 0; XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series = new XYSeries("Scores"); for (Report toolReport : toolResults) { if (!toolReport.isCommercial()) { OverallResult overallResult = toolReport.getOverallResults().getResults(category); series.add(overallResult.falsePositiveRate * 100, overallResult.truePositiveRate * 100); } } for (Report toolReport : toolResults) { if (toolReport.isCommercial()) { OverallResult overallResult = toolReport.getOverallResults().getResults(category); if (!BenchmarkScore.showAveOnlyMode) { series.add(overallResult.falsePositiveRate * 100, overallResult.truePositiveRate * 100); } commercialToolCount++; averageFalseRates.add(overallResult.falsePositiveRate); averageTrueRates.add(overallResult.truePositiveRate); } } for (double d : averageFalseRates) { afr += d; } afr = afr / averageFalseRates.size(); for (double d : averageTrueRates) { atr += d; } atr = atr / averageTrueRates.size(); if (commercialToolCount > 1 || (BenchmarkScore.showAveOnlyMode && commercialToolCount == 1)) { series.add(afr * 100, atr * 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(category, toolResults, xyplot); makeLegend(category, toolResults, 103, 100.5, dataset, xyplot); for (XYDataItem item : (List<XYDataItem>) series.getItems()) { double x = item.getX().doubleValue(); double y = item.getY().doubleValue(); double z = (x + y) / 2; XYLineAnnotation score = new XYLineAnnotation(x, y, z, z, dashed, Color.blue); xyplot.addAnnotation(score); } 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.owasp.benchmark.score.report.ScatterScores.java
private void makeLegend(List<Report> toolResults, int x, int y, XYSeriesCollection dataset, XYPlot xyplot) { char ch = 'A'; int i = 0;/* w w w . j a v a 2s. c o m*/ for (Report r : toolResults) { OverallResults or = r.getOverallResults(); String label = (ch == 'I' ? ch + ": " : "" + ch + ": "); int score = (int) (or.getScore() * 100); String msg = "\u25A0 " + label + r.getToolName() + " (" + 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++; } }