List of usage examples for org.jfree.chart.annotations XYTextAnnotation setPaint
public void setPaint(Paint paint)
From source file:com.che.software.testato.util.jfreechart.LineChartGraphistUtil.java
/** * Colorized and transforms a given JFreeChart. * /*www . j av a2s . c om*/ * @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: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 a 2 s .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: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 . 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: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 ww . j ava2 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: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 . jav a 2s . 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;//from w w w . 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++; } }
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.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 2 s.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++; } }
From source file:com.romraider.logger.ecu.ui.tab.dyno.DynoChartPanel.java
public void startPrompt(String select) { String startPrompt = START_PROMPT; if (select.equalsIgnoreCase("mph")) startPrompt = ET_PROMPT_I;/*from w w w . ja v a 2 s .c om*/ if (select.equalsIgnoreCase("km/h")) startPrompt = ET_PROMPT_M; final double x = ((plot.getDomainAxis().getUpperBound() - plot.getDomainAxis().getLowerBound()) / 2) + plot.getDomainAxis().getLowerBound(); final double y = ((hpAxis.getUpperBound() - hpAxis.getLowerBound()) / 2) + hpAxis.getLowerBound(); final XYTextAnnotation startMessage = new XYTextAnnotation(startPrompt, x, y); startMessage.setPaint(GREEN); startMessage.setTextAnchor(TextAnchor.BOTTOM_CENTER); startMessage.setFont(new Font("Arial", Font.BOLD, 20)); plot.addAnnotation(startMessage); }
From source file:com.romraider.logger.ecu.ui.tab.DynoChartPanel.java
public void startPrompt(String select) { String startPrompt = START_PROMPT; if (select.equalsIgnoreCase("mph")) startPrompt = ET_PROMPT_I;/*from w ww. ja v a 2 s . c o m*/ if (select.equalsIgnoreCase("kph")) startPrompt = ET_PROMPT_M; final double x = ((plot.getDomainAxis().getUpperBound() - plot.getDomainAxis().getLowerBound()) / 2) + plot.getDomainAxis().getLowerBound(); final double y = ((hpAxis.getUpperBound() - hpAxis.getLowerBound()) / 2) + hpAxis.getLowerBound(); final XYTextAnnotation startMessage = new XYTextAnnotation(startPrompt, x, y); startMessage.setPaint(GREEN); startMessage.setTextAnchor(TextAnchor.BOTTOM_CENTER); startMessage.setFont(new Font("Arial", Font.BOLD, 20)); plot.addAnnotation(startMessage); }