List of usage examples for org.jfree.chart ChartFactory createStackedAreaChart
public static JFreeChart createStackedAreaChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls)
From source file:com.thalesgroup.hudson.plugins.cccc.CcccChartBuilder.java
protected JFreeChart createGraph() { JFreeChart chart = ChartFactory.createStackedAreaChart(null, null, "Number of modules", buildDataset(action), PlotOrientation.VERTICAL, true, false, true); chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null);// w w w. j a v a 2 s. co m plot.setForegroundAlpha(0.8f); 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); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // crop extra space around the graph plot.setInsets(new RectangleInsets(0, 0, 0, 5.0)); CategoryItemRenderer firstRender = new DefaultCategoryItemRenderer(); CcccAreaRenderer renderer = new CcccAreaRenderer(action.getUrlName()); plot.setRenderer(firstRender); //Second NumberAxis axis2 = new NumberAxis("Lines of Code"); axis2.setLabelPaint(Color.BLUE); axis2.setAxisLinePaint(Color.BLUE); axis2.setTickLabelPaint(Color.BLUE); CategoryPlot categoryPlot = chart.getCategoryPlot(); categoryPlot.setRangeAxis(1, axis2); //CategoryAxis categoryAxis = categoryPlot.getDomainAxis(); categoryPlot.setDataset(1, buildDataset2(action)); categoryPlot.mapDatasetToRangeAxis(1, 1); CategoryItemRenderer rendu = new DefaultCategoryItemRenderer(); rendu.setBasePaint(Color.BLUE); categoryPlot.setRenderer(1, rendu); //Third NumberAxis axis3 = new NumberAxis("McCabe's Cyclomatic Number"); axis3.setLabelPaint(Color.GREEN); axis3.setAxisLinePaint(Color.GREEN); axis3.setTickLabelPaint(Color.GREEN); CategoryPlot categoryPlot3 = chart.getCategoryPlot(); categoryPlot3.setRangeAxis(2, axis3); categoryPlot3.setDataset(2, buildDataset3(action)); categoryPlot3.mapDatasetToRangeAxis(2, 2); categoryPlot3.mapDatasetToDomainAxis(2, 0); CategoryItemRenderer rendu3 = new DefaultCategoryItemRenderer(); rendu3.setBasePaint(Color.GREEN); categoryPlot3.setRenderer(2, rendu3); return chart; }
From source file:com.googlecode.refit.jenkins.ReFitGraph.java
/** * Creates a chart from the test result data set. * <p>//from w w w . ja v a 2 s. co m * The i-th row of the data set corresponds to the results from the i-th build. * Each row has columns 0, 1, 2 containing the number of failed, skipped and passed tests. * The chart stacks these values from bottom to top, joins the values for the same columns * with lines and fills the areas between the lines with given colours. * <p> * TODO Find out if Jenkins core provides any caching for the chart or the data set. */ @Override protected JFreeChart createGraph() { final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart title null, // domain axis label "count", // range axis label data, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(0.8f); 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(); ChartUtil.adjustChebyshev(data, rangeAxis); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRange(true); StackedAreaRenderer ar = new StackedAreaRenderer2() { private static final long serialVersionUID = 1L; /** * Colour brush for the given data point. */ @Override public Paint getItemPaint(int row, int column) { return super.getItemPaint(row, column); } /** * URL for the given data point, which gets opened when the user clicks on or near * the data point in the chart. */ @Override public String generateURL(CategoryDataset dataset, int row, int column) { ChartLabel label = (ChartLabel) dataset.getColumnKey(column); return label.getUrl(); } /** * Tooltip to be displayed on the chart when the user hovers at or near the * data point. * <p> * The tooltip has the format {@code #17 : 300 Passed}, indicating the build number * and the number of tests with the given result. */ @Override public String generateToolTip(CategoryDataset dataset, int row, int column) { ChartLabel label = (ChartLabel) dataset.getColumnKey(column); TestResult result = label.getResult(); String rowKey = (String) dataset.getRowKey(row); return result.getOwner().getDisplayName() + " : " + dataset.getValue(row, column) + " " + rowKey.substring(1); } }; plot.setRenderer(ar); // Define colours for the data points by column index ar.setSeriesPaint(0, ColorPalette.RED); // Failed ar.setSeriesPaint(1, ColorPalette.YELLOW); // Skipped ar.setSeriesPaint(2, ColorPalette.BLUE); // Passed // crop extra space around the graph plot.setInsets(new RectangleInsets(0, 0, 0, 5.0)); return chart; }
From source file:org.pentaho.chart.plugin.jfreechart.chart.area.JFreeAreaChartGenerator.java
/** * Creates the JFree chart based on the chart document, data provided and * type of chart expected.//from ww w . j a va 2 s . c o m * </p> * @param chartDocContext Chart documument context for the current chart. * @param data Data for the current chart. * @param chartType Area chart type (default, stacked, xy) * @return Returns the JFree chart object (created by the method) */ public JFreeChart createChart(final ChartDocumentContext chartDocContext, final ChartTableModel data, final CSSConstant chartType) { final ChartDocument chartDocument = chartDocContext.getChartDocument(); final String title = getTitle(chartDocument); final String valueCategoryLabel = getValueCategoryLabel(chartDocument); final String valueAxisLabel = getValueAxisLabel(chartDocument); final PlotOrientation orientation = getPlotOrientation(chartDocument); final boolean legend = getShowLegend(chartDocument); final boolean toolTips = getShowToolTips(chartDocument); final DefaultCategoryDataset categoryDataset = datasetGeneratorFactory .createDefaultCategoryDataset(chartDocContext, data); if (categoryDataset == null) { logger.error(Messages.getErrorString("JFreeChartFactoryEngine.ERROR_0001_DATASET_IS_NULL")); //$NON-NLS-1$ return null; } JFreeChart chart = null; if (ChartAreaStyle.STACKED.equals(chartType)) { chart = ChartFactory.createStackedAreaChart(title, valueCategoryLabel, valueAxisLabel, categoryDataset, orientation, legend, toolTips, false); } else if (ChartAreaStyle.XY.equals(chartType)) { } else { chart = ChartFactory.createAreaChart(title, valueCategoryLabel, valueAxisLabel, categoryDataset, orientation, legend, toolTips, false); } if (chart != null) { final ChartElement[] seriesElements = chartDocument.getRootElement() .findChildrenByName(ChartElement.TAG_NAME_SERIES); final CategoryPlot categoryPlot = chart.getCategoryPlot(); if (seriesElements != null && categoryPlot != null) { setSeriesAttributes(seriesElements, data, categoryPlot); } } return chart; }
From source file:org.jfree.chart.demo.StackedAreaChartDemo.java
/** * Creates a sample chart.// ww w.j a v a2s.co m * * @param dataset the dataset. * * @return A sample chart. */ public JFreeChart createChart(CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createStackedAreaChart("Stacked Area Chart", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, false); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setForegroundAlpha(0.5f); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); // change the auto tick unit selection to integer units only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); final CategoryItemRenderer renderer = plot.getRenderer(); renderer.setItemLabelsVisible(true); return chart; }
From source file:edu.ucla.stat.SOCR.chart.demo.StackedAreaChartDemo.java
/** * Creates a sample chart.// ww w.j a v a 2 s. c o m * * @param dataset the dataset. * * @return A sample chart. */ protected JFreeChart createChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createStackedAreaChart(chartTitle, // chart title domainLabel, // domain axis label rangeLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation !legendPanelOn, // include legend true, false); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setForegroundAlpha(0.85f); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); // change the auto tick unit selection to integer units only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); CategoryItemRenderer renderer = plot.getRenderer(); renderer.setBaseItemLabelsVisible(true); AreaRenderer renderer2 = (AreaRenderer) plot.getRenderer(); renderer2.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); return chart; }
From source file:hudson.plugins.labeledgroupedtests.TrendGraph.java
protected JFreeChart createGraph() { final CategoryDataset dataset = createDataSet().build(); final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart // title null, // unused yLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // urls );//from w ww. j av a2 s. c o m chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); 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(); ChartUtil.adjustChebyshev(dataset, rangeAxis); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRange(true); StackedAreaRenderer ar = new StackedAreaRenderer2() { @Override public Paint getItemPaint(int row, int column) { ChartLabel key = (ChartLabel) dataset.getColumnKey(column); if (key.getColor() != null) return key.getColor(); return super.getItemPaint(row, column); } @Override public String generateURL(CategoryDataset dataset, int row, int column) { ChartLabel label = (ChartLabel) dataset.getColumnKey(column); return label.getURL() + relativeUrl; } @Override public String generateToolTip(CategoryDataset dataset, int row, int column) { ChartLabel label = (ChartLabel) dataset.getColumnKey(column); return label.getToolTipText(); } }; plot.setRenderer(ar); ar.setSeriesPaint(0, ColorPalette.RED); // Skips. ar.setSeriesPaint(1, ColorPalette.YELLOW); // Failures. ar.setSeriesPaint(2, ColorPalette.BLUE); // Total. // crop extra space around the graph plot.setInsets(new RectangleInsets(0, 0, 0, 5.0)); return chart; }
From source file:hudson.plugins.robot.graph.RobotGraph.java
/** * Creates a Robot trend graph/*from w w w. ja v a 2 s. c o m*/ * @return the JFreeChart graph object */ protected JFreeChart createGraph() { final JFreeChart chart = ChartFactory.createStackedAreaChart(null, null, yLabel, categoryDataset, PlotOrientation.VERTICAL, true, true, false); final LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.RIGHT); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setForegroundAlpha(0.7f); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.darkGray); final CategoryAxis domainAxis = new ShiftedCategoryAxis(xLabel); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); plot.setDomainAxis(domainAxis); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); if (binaryData) { rangeAxis.setUpperBound(1); } else if (upperBound != 0) { rangeAxis.setUpperBound(upperBound); } else { rangeAxis.setAutoRange(true); } rangeAxis.setLowerBound(lowerBound); Font font = new Font("Dialog", Font.PLAIN, fontSize); plot.getDomainAxis().setLabelFont(font); plot.getDomainAxis().setTickLabelFont(font); plot.getRangeAxis().setLabelFont(font); plot.getRangeAxis().setTickLabelFont(font); legend.setItemFont(font); final CategoryItemRenderer renderer = plot.getRenderer(); for (int i = 0; i < colors.length; i++) { renderer.setSeriesPaint(i, colors[i]); } plot.setInsets(new RectangleInsets(15.0, 0, 0, 5.0)); return chart; }
From source file:hudson.graph.jfreechart.JFreeChartSupport.java
public JFreeChart createChart() { if (chartType == Graph.TYPE_STACKED_AREA) { jFreeChart = ChartFactory.createStackedAreaChart(null, // chart chartTitle, // // title xAxisLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // urls );/*ww w .j av a 2 s . com*/ } else if (chartType == Graph.TYPE_LINE) { jFreeChart = ChartFactory.createLineChart(null, // chart title chartTitle, // // title xAxisLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); } jFreeChart.setBackgroundPaint(Color.white); final CategoryPlot plot = jFreeChart.getCategoryPlot(); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); 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); if (chartType == Graph.TYPE_LINE) { final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseStroke(new BasicStroke(3)); if (multiStageTimeSeries != null) { for (int i = 0; i < multiStageTimeSeries.size(); i++) { renderer.setSeriesPaint(i, multiStageTimeSeries.get(i).color); } } } 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(); Utils.adjustChebyshev(dataset, rangeAxis); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); if (chartType == Graph.TYPE_STACKED_AREA) { StackedAreaRenderer ar = new StackedAreaRenderer2() { @Override public Paint getItemPaint(int row, int column) { if (row == 2) { return ColorPalette.BLUE; } if (row == 1) { return ColorPalette.YELLOW; } if (row == 0) { return ColorPalette.RED; } ChartLabel key = (ChartLabel) dataset.getColumnKey(column); return key.getColor(row, column); } @Override public String generateURL(CategoryDataset dataset, int row, int column) { ChartLabel label = (ChartLabel) dataset.getColumnKey(column); return label.getLink(row, column); } @Override public String generateToolTip(CategoryDataset dataset, int row, int column) { ChartLabel label = (ChartLabel) dataset.getColumnKey(column); return label.getToolTip(row, column); } }; plot.setRenderer(ar); ar.setSeriesPaint(0, ColorPalette.RED); // Failures. ar.setSeriesPaint(1, ColorPalette.YELLOW); // Skips. ar.setSeriesPaint(2, ColorPalette.BLUE); // Total. } // crop extra space around the graph plot.setInsets(new RectangleInsets(0, 0, 0, 5.0)); return jFreeChart; }
From source file:com.cwctravel.hudson.plugins.suitegroupedtests.TrendGraph.java
@Override protected JFreeChart createGraph() { final CategoryDataset dataset = createDataSet().build(); final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart // title null, // unused yLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // urls );/*from w w w .j av a2 s .c om*/ chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); 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(); ChartUtil.adjustChebyshev(dataset, rangeAxis); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRange(true); StackedAreaRenderer ar = new StackedAreaRenderer2() { private static final long serialVersionUID = 7962375662395944968L; @Override public Paint getItemPaint(int row, int column) { ChartLabel key = (ChartLabel) dataset.getColumnKey(column); if (key.getColor() != null) return key.getColor(); return super.getItemPaint(row, column); } @Override public String generateURL(CategoryDataset dataset, int row, int column) { ChartLabel label = (ChartLabel) dataset.getColumnKey(column); return label.getURL() + relativeUrl; } @Override public String generateToolTip(CategoryDataset dataset, int row, int column) { ChartLabel label = (ChartLabel) dataset.getColumnKey(column); return label.getToolTipText(); } }; plot.setRenderer(ar); ar.setSeriesPaint(0, ColorPalette.RED); // Skips. ar.setSeriesPaint(1, ColorPalette.YELLOW); // Failures. ar.setSeriesPaint(2, ColorPalette.BLUE); // Total. // crop extra space around the graph plot.setInsets(new RectangleInsets(0, 0, 0, 5.0)); return chart; }
From source file:com.cwctravel.hudson.plugins.multimoduletests.TrendGraph.java
@Override protected JFreeChart createGraph() { final CategoryDataset dataset = createDataSet().build(); final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart // title null, // unused yLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // urls );/*w w w . j av a 2s .c o m*/ chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); 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(); ChartUtil.adjustChebyshev(dataset, rangeAxis); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRange(true); StackedAreaRenderer ar = new StackedAreaRenderer2() { private static final long serialVersionUID = 7962375662395944968L; @Override public Paint getItemPaint(int row, int column) { ChartLabel key = (ChartLabel) dataset.getColumnKey(column); if (key.getColor() != null) return key.getColor(); return super.getItemPaint(row, column); } @Override public String generateURL(CategoryDataset dataset, int row, int column) { ChartLabel label = (ChartLabel) dataset.getColumnKey(column); return prefixUrl + label.getURL() + suffixUrl; } @Override public String generateToolTip(CategoryDataset dataset, int row, int column) { ChartLabel label = (ChartLabel) dataset.getColumnKey(column); return label.getToolTipText(); } }; plot.setRenderer(ar); ar.setSeriesPaint(0, ColorPalette.RED); // Skips. ar.setSeriesPaint(1, ColorPalette.YELLOW); // Failures. ar.setSeriesPaint(2, ColorPalette.BLUE); // Total. // crop extra space around the graph plot.setInsets(new RectangleInsets(0, 0, 0, 5.0)); return chart; }