List of usage examples for org.jfree.chart JFreeChart getCategoryPlot
public CategoryPlot getCategoryPlot()
From source file:org.tap4j.plugin.util.GraphHelper.java
/** * Creates the graph displayed on Method results page to compare execution * duration and status of a test method across builds. * /*from w w w .j a v a 2 s. c o m*/ * At max, 9 older builds are displayed. * * @param req * request * @param dataset * data set to be displayed on the graph * @param statusMap * a map with build as key and the test methods execution status * (result) as the value * @param methodUrl * URL to get to the method from a build test result page * @return the chart */ public static JFreeChart createMethodChart(StaplerRequest req, final CategoryDataset dataset, final Map<NumberOnlyBuildLabel, String> statusMap, final String methodUrl) { final JFreeChart chart = ChartFactory.createBarChart(null, // chart // title null, // unused " Duration (secs)", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips true // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); chart.removeLegend(); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(0.8f); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); BarRenderer br = new BarRenderer() { private static final long serialVersionUID = 961671076462240008L; Map<String, Paint> statusPaintMap = new HashMap<String, Paint>(); { statusPaintMap.put("PASS", ColorPalette.BLUE); statusPaintMap.put("SKIP", ColorPalette.YELLOW); statusPaintMap.put("FAIL", ColorPalette.RED); } /** * Returns the paint for an item. Overrides the default behavior * inherited from AbstractSeriesRenderer. * * @param row * the series. * @param column * the category. * * @return The item color. */ public Paint getItemPaint(final int row, final int column) { NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column); Paint paint = statusPaintMap.get(statusMap.get(label)); // when the status of test method is unknown, use gray color return paint == null ? Color.gray : paint; } }; br.setBaseToolTipGenerator(new CategoryToolTipGenerator() { public String generateToolTip(CategoryDataset dataset, int row, int column) { NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column); if ("UNKNOWN".equals(statusMap.get(label))) { return "unknown"; } // values are in seconds return dataset.getValue(row, column) + " secs"; } }); br.setBaseItemURLGenerator(new CategoryURLGenerator() { public String generateURL(CategoryDataset dataset, int series, int category) { NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(category); if ("UNKNOWN".equals(statusMap.get(label))) { // no link when method result doesn't exist return null; } // return label.build.getUpUrl() + label.build.getNumber() + "/" + PluginImpl.URL + "/" + methodUrl; return label.build.getUpUrl() + label.build.getNumber() + "/tap/" + methodUrl; } }); br.setItemMargin(0.0); br.setMinimumBarLength(5); // set the base to be 1/100th of the maximum value displayed in the // graph br.setBase(br.findRangeBounds(dataset).getUpperBound() / 100); plot.setRenderer(br); // crop extra space around the graph plot.setInsets(new RectangleInsets(0, 0, 0, 5.0)); return chart; }
From source file:hudson.plugins.codecover.portlet.chart.CodeCoverBuilderTrendChart.java
/** * Creates a graph for CodeCover Coverage results. * * @param summaries//from w w w .j a v a2 s.c o m * HashMap(key = run date and value = Instrumentation tests * results) * @param widthParam * the chart width * @param heightParam * the chart height * @return Graph (JFreeChart) */ private static Graph createTrendChart(final Map<LocalDate, CodeCoverCoverageResultSummary> summaries, int widthParam, int heightParam) { return new Graph(-1, widthParam, heightParam) { @Override protected JFreeChart createGraph() { // Show empty chart if (summaries == null) { JFreeChart chart = ChartFactory.createStackedAreaChart(null, Constants.AXIS_LABEL, Constants.AXIS_LABEL_VALUE, null, PlotOrientation.VERTICAL, true, false, false); return chart; } int lineNumber = 0; JFreeChart chart = ChartFactory.createLineChart("", Constants.AXIS_LABEL, Constants.AXIS_LABEL_VALUE, buildDataSet(summaries), PlotOrientation.VERTICAL, true, false, false); chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); // Line thickness CategoryItemRenderer renderer = plot.getRenderer(); BasicStroke stroke = new BasicStroke(Constants.LINE_THICKNESS, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); renderer.setSeriesStroke(lineNumber++, stroke); renderer.setSeriesStroke(lineNumber++, stroke); renderer.setSeriesStroke(lineNumber++, stroke); renderer.setSeriesStroke(lineNumber, stroke); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(Constants.FOREGROUND_ALPHA); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(Constants.DEFAULT_MARGIN); domainAxis.setUpperMargin(Constants.DEFAULT_MARGIN); domainAxis.setCategoryMargin(Constants.DEFAULT_MARGIN); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperBound(Constants.UPPER_BOUND); rangeAxis.setLowerBound(Constants.LOWER_BOUND); return chart; } }; }
From source file:hudson.plugins.karma.portlet.chart.KarmaBuilderTrendChart.java
/** * Creates a graph for Karma Coverage results. * * @param summaries/* w w w . j av a 2s . c o m*/ * HashMap(key = run date and value = Instrumentation tests * results) * @param widthParam * the chart width * @param heightParam * the chart height * @return Graph (JFreeChart) */ private static Graph createTrendChart(final Map<LocalDate, KarmaCoverageResultSummary> summaries, int widthParam, int heightParam) { return new Graph(-1, widthParam, heightParam) { @Override protected JFreeChart createGraph() { // Show empty chart if (summaries == null) { JFreeChart chart = ChartFactory.createStackedAreaChart(null, Constants.AXIS_LABEL, Constants.AXIS_LABEL_VALUE, null, PlotOrientation.VERTICAL, true, false, false); return chart; } int lineNumber = 0; JFreeChart chart = ChartFactory.createLineChart("", Constants.AXIS_LABEL, Constants.AXIS_LABEL_VALUE, buildDataSet(summaries), PlotOrientation.VERTICAL, true, false, false); chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); // Line thickness CategoryItemRenderer renderer = plot.getRenderer(); BasicStroke stroke = new BasicStroke(Constants.LINE_THICKNESS, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); renderer.setSeriesStroke(lineNumber++, stroke); renderer.setSeriesStroke(lineNumber++, stroke); renderer.setSeriesStroke(lineNumber++, stroke); renderer.setSeriesStroke(lineNumber, stroke); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(Constants.FOREGROUND_ALPHA); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(Constants.DEFAULT_MARGIN); domainAxis.setUpperMargin(Constants.DEFAULT_MARGIN); domainAxis.setCategoryMargin(Constants.DEFAULT_MARGIN); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperBound(Constants.UPPER_BOUND); rangeAxis.setLowerBound(Constants.LOWER_BOUND); return chart; } }; }
From source file:hudson.plugins.emma.portlet.chart.EmmaBuilderTrendChart.java
/** * Creates a graph for Emma Coverage results. * * @param summaries//from w w w . j a v a 2 s . co m * HashMap(key = run date and value = Instrumentation tests * results) * @param widthParam * the chart width * @param heightParam * the chart height * @return Graph (JFreeChart) */ private static Graph createTrendChart(final Map<LocalDate, EmmaCoverageResultSummary> summaries, int widthParam, int heightParam) { return new Graph(-1, widthParam, heightParam) { @Override protected JFreeChart createGraph() { // Show empty chart if (summaries == null) { JFreeChart chart = ChartFactory.createStackedAreaChart(null, Constants.AXIS_LABEL, Constants.AXIS_LABEL_VALUE, null, PlotOrientation.VERTICAL, true, false, false); return chart; } int lineNumber = 0; JFreeChart chart = ChartFactory.createLineChart("", Constants.AXIS_LABEL, Constants.AXIS_LABEL_VALUE, buildDataSet(summaries), PlotOrientation.VERTICAL, true, false, false); chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); // Line thickness CategoryItemRenderer renderer = plot.getRenderer(); BasicStroke stroke = new BasicStroke(Constants.LINE_THICKNESS, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); renderer.setSeriesStroke(lineNumber++, stroke); renderer.setSeriesStroke(lineNumber++, stroke); renderer.setSeriesStroke(lineNumber++, stroke); renderer.setSeriesStroke(lineNumber, stroke); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(Constants.FOREGROUND_ALPHA); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(Constants.DEFAULT_MARGIN); domainAxis.setUpperMargin(Constants.DEFAULT_MARGIN); domainAxis.setCategoryMargin(Constants.DEFAULT_MARGIN); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperBound(Constants.UPPER_BOUND); rangeAxis.setLowerBound(Constants.LOWER_BOUND); return chart; } }; }
From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java
/** * DOC Zqin Comment method "createBoxAndWhiskerChart". * /*w w w.ja v a 2 s .co m*/ * @param title * @param dataset * @return */ public static JFreeChart createBoxAndWhiskerChart(String title, BoxAndWhiskerCategoryDataset dataset) { // ADD msjian TDQ-5112 2012-4-10: after upgrate to jfreechart-1.0.12.jar, change the default chart wallPaint ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); // TDQ-5112~ JFreeChart chart = ChartFactory.createBoxAndWhiskerChart(null, title, Messages.getString("TopChartFactory.Value"), dataset, false); //$NON-NLS-1$ CategoryPlot plot = chart.getCategoryPlot(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRange(false); double min = dataset.getMinRegularValue("0", "").doubleValue(); //$NON-NLS-1$ //$NON-NLS-2$ double max = dataset.getMaxRegularValue("0", "").doubleValue(); //$NON-NLS-1$ //$NON-NLS-2$ double unit = (max - min) / 10; rangeAxis.setRange(min - unit, max + unit); rangeAxis.setTickUnit(new NumberTickUnit(unit)); BoxAndWhiskerRenderer renderer = (BoxAndWhiskerRenderer) plot.getRenderer(); renderer.setArtifactPaint(ChartDecorator.COLOR_LIST.get(1)); return chart; }
From source file:hudson.plugins.jacoco.portlet.chart.JacocoBuilderTrendChart.java
/** * Creates a graph for JaCoCo Coverage results. * * @param summaries/*from www . ja v a 2 s . c o m*/ * HashMap(key = run date and value = Instrumentation tests * results) * @param widthParam * the chart width * @param heightParam * the chart height * @return Graph (JFreeChart) */ private static Graph createTrendChart(final Map<LocalDate, JacocoCoverageResultSummary> summaries, int widthParam, int heightParam) { return new Graph(-1, widthParam, heightParam) { @Override protected JFreeChart createGraph() { // Show empty chart if (summaries == null) { JFreeChart chart = ChartFactory.createStackedAreaChart(null, Constants.AXIS_LABEL, Constants.AXIS_LABEL_VALUE, null, PlotOrientation.VERTICAL, true, false, false); return chart; } int lineNumber = 0; JFreeChart chart = ChartFactory.createLineChart("", Constants.AXIS_LABEL, Constants.AXIS_LABEL_VALUE, buildDataSet(summaries), PlotOrientation.VERTICAL, true, false, false); chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); // Line thickness CategoryItemRenderer renderer = plot.getRenderer(); BasicStroke stroke = new BasicStroke(Constants.LINE_THICKNESS, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); renderer.setSeriesStroke(lineNumber++, stroke); renderer.setSeriesStroke(lineNumber++, stroke); renderer.setSeriesStroke(lineNumber++, stroke); renderer.setSeriesStroke(lineNumber, stroke); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(Constants.FOREGROUND_ALPHA); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(Constants.DEFAULT_MARGIN); domainAxis.setUpperMargin(Constants.DEFAULT_MARGIN); domainAxis.setCategoryMargin(Constants.DEFAULT_MARGIN); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); //rangeAxis.setUpperBound(Constants.UPPER_BOUND); rangeAxis.setLowerBound(Constants.LOWER_BOUND); return chart; } }; }
From source file:org.talend.dataprofiler.chart.ChartDecorator.java
public static void decorateStackedBarChart(JFreeChart chart, PlotOrientation orientation) { if (chart != null) { Plot plot = chart.getPlot();/*from w ww .j a va 2 s .c o m*/ if (plot instanceof CategoryPlot) { decorateCategoryPlot(chart, orientation); int rowCount = chart.getCategoryPlot().getDataset().getRowCount(); for (int i = 0; i < rowCount; i++) { if (i >= STACK_BAR_COLOR_LIST.size()) { STACK_BAR_COLOR_LIST.add(generateRandomColor(STACK_BAR_COLOR_LIST)); } ((CategoryPlot) plot).getRenderer().setSeriesPaint(i, STACK_BAR_COLOR_LIST.get(i)); } } } }
From source file:org.talend.dataprofiler.chart.ChartDecorator.java
/** * // www. j a v a2 s . c o m * decorate concept chart on semantic Analysis wizard. * * @param chart * @param orientation */ public static void decorateConceptChart(JFreeChart chart, PlotOrientation orientation) { if (chart == null) { return; } Plot plot = chart.getPlot(); if (plot instanceof CategoryPlot) { decorateCategoryPlot(chart, orientation); int rowCount = chart.getCategoryPlot().getDataset().getRowCount(); for (int i = 0; i < rowCount; i++) { ((CategoryPlot) plot).getRenderer().setSeriesPaint(i, PluginConstant.PRIMARY_BLUE_AWT); } } }
From source file:presentation.webgui.vitroappservlet.StyleCreator.java
private static JFreeChart createChart(CategoryDataset dataset, Vector<String> givCategColors, Model3dStylesEntry givStyleEntry) { String capSimpleName = givStyleEntry.getCorrCapability(); capSimpleName = capSimpleName.replaceAll(Capability.dcaPrefix, ""); JFreeChart chart = ChartFactory.createBarChart("Style Legend for " + capSimpleName, // chart title null, // domain axis label null, // range axis label dataset, // data PlotOrientation.HORIZONTAL, false, // include legend true, false);/*w w w . j a v a 2 s . c om*/ chart.getTitle().setFont(new Font("SansSerif", Font.BOLD, 14)); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); // seen CategoryPlot plot = chart.getCategoryPlot(); chart.setPadding(new RectangleInsets(0, 0, 0, 0)); //new plot.setNoDataMessage("NO DATA!"); Paint[] tmpPaintCategories = { Color.white }; if (givCategColors.size() > 0) { tmpPaintCategories = new Paint[givCategColors.size()]; for (int i = 0; i < givCategColors.size(); i++) { tmpPaintCategories[i] = Color.decode(givCategColors.elementAt(i)); } } CategoryItemRenderer renderer = new CustomRenderer(tmpPaintCategories); renderer.setSeriesPaint(0, new Color(255, 204, 51)); //new plot.setRenderer(renderer); plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); //new plot.setForegroundAlpha(1f); //new plot.setBackgroundAlpha(1f); //new plot.setInsets(new RectangleInsets(5, 0, 5, 0)); //new was 5,0,5,0 plot.setRangeGridlinesVisible(false); //new was true plot.setBackgroundPaint(Color.white);//new: was (Color.lightGray); plot.setOutlinePaint(Color.white); //plot.setOrientation(PlotOrientation.HORIZONTAL); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.04); domainAxis.setUpperMargin(0.04); domainAxis.setVisible(true); domainAxis.setLabelAngle(Math.PI / 2); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setRange(0.0, 100.0); // new: was 100 rangeAxis.setVisible(false); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:org.tap4j.plugin.util.GraphHelper.java
public static JFreeChart createChart(StaplerRequest req, CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createStackedAreaChart("TAP Tests", // chart title null, // unused "TAP Tests Count", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls );//from w w w . j a v a 2s.c om // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... final LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.RIGHT); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(0.8f); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); StackedAreaRenderer ar = new StackedAreaRenderer2() { private static final long serialVersionUID = 331915263367089058L; @Override public String generateURL(CategoryDataset dataset, int row, int column) { NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column); return label.build.getNumber() + "/" + AbstractTapProjectAction.URL_NAME + "/"; } @Override public String generateToolTip(CategoryDataset dataset, int row, int column) { NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column); TapBuildAction build = label.build.getAction(TapBuildAction.class); TapResult report = build.getResult(); report.tally(); switch (row) { case 0: return String.valueOf(report.getFailed()) + " Failure(s)"; case 1: return String.valueOf(report.getPassed()) + " Pass"; case 2: return String.valueOf(report.getSkipped()) + " Skip(s)"; default: return ""; } } }; plot.setRenderer(ar); ar.setSeriesPaint(0, ColorPalette.RED); // Failures ar.setSeriesPaint(1, ColorPalette.BLUE); // Pass ar.setSeriesPaint(2, ColorPalette.YELLOW); // Skips // crop extra space around the graph plot.setInsets(new RectangleInsets(0, 0, 0, 5.0)); return chart; }