List of usage examples for org.jfree.chart.axis CategoryAxis setLowerMargin
public void setLowerMargin(double margin)
From source file:org.operamasks.faces.render.graph.ChartRenderer.java
private void setCategoryAxisStyles(CategoryAxis axis, UIAxis comp) { Double lowerMargin = comp.getLowerMargin(); Double upperMargin = comp.getUpperMargin(); if (lowerMargin != null) axis.setLowerMargin(lowerMargin); if (upperMargin != null) axis.setUpperMargin(upperMargin); Double labelAngle = comp.getLabelAngle(); if (labelAngle != null) { CategoryLabelPositions clp;// ww w . jav a 2s. c o m double angle = Math.PI * labelAngle / 180.0; if (angle >= 0) { clp = CategoryLabelPositions.createDownRotationLabelPositions(angle); } else { clp = CategoryLabelPositions.createUpRotationLabelPositions(-angle); } axis.setCategoryLabelPositions(clp); } }
From source file:edu.ucla.stat.SOCR.chart.demo.DotChart.java
protected JFreeChart createChart2(BoxAndWhiskerCategoryDataset dataset) { //System.out.println("createChart2 called"); CategoryAxis domainAxis = new CategoryAxis(null); // NumberAxis rangeAxis = new NumberAxis("X"); // System.out.println("using the common RangeAxis\n"); common_rangeAxis.setAutoRange(false); // NumberAxis rangeAxis = common_rangeAxis; BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); CategoryPlot plot = new CategoryPlot(dataset, domainAxis, common_rangeAxis, renderer); JFreeChart chart = new JFreeChart("", plot); chart.setBackgroundPaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.lightGray); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.lightGray); plot.setOrientation(PlotOrientation.HORIZONTAL); //rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); renderer.setFillBox(false);/*ww w. j a v a2s .co m*/ // renderer.setLegendItemLabelGenerator(new SOCRCategoryCellLabelGenerator(dataset, values_storage,SERIES_COUNT, CATEGORY_COUNT)); domainAxis.setLowerMargin(0.46); domainAxis.setUpperMargin(0.46); chart.removeLegend(); return chart; }
From source file:edu.ucla.stat.SOCR.analyses.gui.Chart.java
private JFreeChart createBoxAndWhiskerChart(String title, String xLabel, String yLabel, BoxAndWhiskerCategoryDataset dataset) { CategoryAxis domainAxis = new CategoryAxis(xLabel); NumberAxis rangeAxis = new NumberAxis(yLabel); // CategoryItemRenderer renderer = new BoxAndWhiskerRenderer(); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer); JFreeChart chart = new JFreeChart(title, plot); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); //columnCount -- category count //RowCount -- serie count if (dataset.getColumnCount() * dataset.getRowCount() < 5) { domainAxis.setLowerMargin(0.2); domainAxis.setUpperMargin(0.2);//from w ww.j av a 2s.c om if (dataset.getColumnCount() == 1) renderer.setItemMargin(0.5); // domainAxis.setCategoryMargin(domainAxis.getCategoryMargin()*2); //System.out.println("lowerMargin="+domainAxis.getLowerMargin()); //System.out.println("ItemMargin="+renderer.getItemMargin()); //System.out.println("CategoryMargin="+domainAxis.getCategoryMargin()); } else if (dataset.getColumnCount() * dataset.getRowCount() < 10) { domainAxis.setLowerMargin(domainAxis.getLowerMargin() * 2); domainAxis.setUpperMargin(domainAxis.getUpperMargin() * 2); if (dataset.getColumnCount() == 1) renderer.setItemMargin(renderer.getItemMargin() * 2); else domainAxis.setCategoryMargin(domainAxis.getCategoryMargin() * 2); //System.out.println("lowerMargin="+domainAxis.getLowerMargin()); //System.out.println("ItemMargin="+renderer.getItemMargin()); //System.out.println("CategoryMargin="+domainAxis.getCategoryMargin()); } return chart; }
From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java
private byte[] generateBoxAndWhiskerChart(BoxAndWhiskerCategoryDataset dataset, int width, int height) { JFreeChart chart = ChartFactory.createBoxAndWhiskerChart(null, null, null, dataset, false); // set background chart.setBackgroundPaint(parseColor(statsManager.getChartBackgroundColor())); // set chart border chart.setPadding(new RectangleInsets(10, 5, 5, 5)); chart.setBorderVisible(true);//w w w . ja v a2 s. c o m chart.setBorderPaint(parseColor("#cccccc")); // set anti alias chart.setAntiAlias(true); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis(); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); BufferedImage img = chart.createBufferedImage(width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { ImageIO.write(img, "png", out); } catch (IOException e) { log.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java
private byte[] createToolAnalysisChart(int width, int height) { CategoryDataset dataset = getToolAnalysisDataSet(); if (dataset == null) { return generateNoDataChart(width, height); }/*from w ww . j a va 2 s. c o m*/ JFreeChart chart = ChartFactory.createBarChart(null, // chart title null, // domain axis label null, // range axis label dataset, // data PlotOrientation.HORIZONTAL, // the plot orientation false, // legend false, // tooltips false // urls ); // set background chart.setBackgroundPaint(parseColor(statsManager.getChartBackgroundColor())); // set chart border chart.setPadding(new RectangleInsets(10, 5, 5, 5)); chart.setBorderVisible(true); chart.setBorderPaint(parseColor("#cccccc")); // set anti alias chart.setAntiAlias(true); CategoryPlot plot = (CategoryPlot) chart.getPlot(); // set transparency plot.setForegroundAlpha(0.7f); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setVisible(false); domainAxis.setUpperMargin(0); domainAxis.setLowerMargin(0); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setUpperMargin(0.20); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); BarRenderer renderer = (BarRenderer) plot.getRenderer(); CategoryItemLabelGenerator generator = new StandardCategoryItemLabelGenerator("{1}", NumberFormat.getInstance(new ResourceLoader().getLocale())); renderer.setBaseItemLabelGenerator(generator); renderer.setBaseItemLabelFont(new Font("SansSerif", Font.PLAIN, 9)); renderer.setBaseItemLabelsVisible(true); renderer.setItemMargin(0); renderer.setSeriesPaint(0, Color.BLUE); BufferedImage img = chart.createBufferedImage(width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { ImageIO.write(img, "png", out); } catch (IOException e) { log.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
From source file:msi.gama.outputs.layers.ChartLayerStatement.java
/** * create dataset for box_whisker chart/*from ww w .j a v a2s. c o m*/ * @return A sample dataset. */ private BoxAndWhiskerCategoryDataset createWhisker(final IScope scope) { final CategoryPlot plot = (CategoryPlot) chart.getPlot(); // final int seriesCount = 1; final int categoryCount = 3; final int entityCount = 2; final DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); for (int i = 0; i < datas.size(); i++) { // ChartData e = datas.get(i); for (int j = 0; j < categoryCount; j++) { final List list = new ArrayList(); // add some values... for (int k = 0; k < entityCount; k++) { // list.add(new Double(k*2)); // list.add(new Double(k*3)); final double value1 = 10.0 + Math.random() * 3; list.add(new Double(value1)); final double value2 = 11.25 + Math.random(); // concentrate values in the middle list.add(new Double(value2)); } dataset.add(list, "Series " + i, " Type " + j); history.append("Series " + i); history.append(','); } } history.deleteCharAt(history.length() - 1); history.append(Strings.LN); plot.setDataset(dataset); chart.removeLegend(); final CategoryAxis axis = plot.getDomainAxis(); axis.setTickLabelFont(getTickFont()); axis.setLabelFont(getLabelFont()); // ((BarRenderer3D) plot.getRenderer()).setItemMargin(0.1); axis.setCategoryMargin(0.1); axis.setUpperMargin(0.05); axis.setLowerMargin(0.05); return dataset; }
From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java
private byte[] generateLayeredBarChart(CategoryDataset dataset, int width, int height) { JFreeChart chart = ChartFactory.createBarChart(null, // chart title null, // domain axis label null, // range axis label dataset, // data PlotOrientation.VERTICAL, // the plot orientation true, // legend true, // tooltips false // urls );/*from ww w .java 2 s . c o m*/ // set background chart.setBackgroundPaint(parseColor(statsManager.getChartBackgroundColor())); // set chart border chart.setPadding(new RectangleInsets(10, 5, 5, 5)); chart.setBorderVisible(true); chart.setBorderPaint(parseColor("#cccccc")); // set anti alias chart.setAntiAlias(true); CategoryPlot plot = (CategoryPlot) chart.getPlot(); // disable bar outlines... LayeredBarRenderer renderer = new LayeredBarRenderer(); renderer.setDrawBarOutline(false); renderer.setSeriesBarWidth(0, .6); renderer.setSeriesBarWidth(1, .8); renderer.setSeriesBarWidth(2, 1.0); plot.setRenderer(renderer); // for this renderer, we need to draw the first series last... plot.setRowRenderingOrder(SortOrder.DESCENDING); // set up gradient paints for series... GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0)); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); BufferedImage img = chart.createBufferedImage(width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { ImageIO.write(img, "png", out); } catch (IOException e) { log.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java
private byte[] generateStackedAreaChart(CategoryDataset dataset, int width, int height) { JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart title null, // domain axis label null, // range axis label dataset, // data PlotOrientation.VERTICAL, // the plot orientation true, // legend true, // tooltips false // urls );/*from www .j a v a 2 s . c o m*/ // set background chart.setBackgroundPaint(parseColor(statsManager.getChartBackgroundColor())); // set chart border chart.setPadding(new RectangleInsets(10, 5, 5, 5)); chart.setBorderVisible(true); chart.setBorderPaint(parseColor("#cccccc")); // set anti alias chart.setAntiAlias(true); CategoryPlot plot = (CategoryPlot) chart.getPlot(); // set transparency plot.setForegroundAlpha(0.7f); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); // set colour of regular users using Karate belt colour: white, green, blue, brown, black/gold CategoryItemRenderer renderer = plot.getRenderer(); renderer.setSeriesPaint(0, new Color(205, 173, 0)); // gold users renderer.setSeriesPaint(1, new Color(139, 69, 19)); renderer.setSeriesPaint(2, Color.BLUE); renderer.setSeriesPaint(3, Color.GREEN); renderer.setSeriesPaint(4, Color.WHITE); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); BufferedImage img = chart.createBufferedImage(width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { ImageIO.write(img, "png", out); } catch (IOException e) { log.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
From source file:msi.gama.outputs.layers.ChartLayerStatement.java
private void createBars(final IScope scope) { final CategoryPlot plot = (CategoryPlot) chart.getPlot(); BarRenderer renderer = new CustomRenderer(); plot.setRenderer(renderer);// w w w.j a v a2 s .c om dataset = new DefaultCategoryDataset(); int i = 0; for (final ChartData e : datas) { // String legend = e.getName(); // ((DefaultCategoryDataset) dataset).setValue(0d, new Integer(0), legend/* , legend */); final String legend = e.getName(); if (!CategoryItemRenderer.class.isInstance(e.getRenderer())) { e.renderer = new CustomRenderer(); } plot.setRenderer(i, (CategoryItemRenderer) e.getRenderer(), false); final Color c = e.getColor(); plot.getRenderer(i).setSeriesPaint(0, c); // plot.setDataset(i, (DefaultCategoryDataset) dataset); i++; history.append(legend); history.append(','); } if (history.length() > 0) { history.deleteCharAt(history.length() - 1); } history.append(Strings.LN); plot.setDataset((DefaultCategoryDataset) dataset); chart.removeLegend(); final NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setTickLabelFont(getTickFont()); yAxis.setLabelFont(getLabelFont()); IExpression expr = getFacet(YRANGE); IExpression expr2 = getFacet(YTICKUNIT); if (expr != null) { Object range = expr.value(scope); // Double range = Cast.asFloat(scope, expr.value(scope)); if (range instanceof Number) { double r = ((Number) range).doubleValue(); if (r > 0) { yAxis.setFixedAutoRange(r); yAxis.setAutoRangeMinimumSize(r); } // yAxis.setAutoRangeIncludesZero(false); } else if (range instanceof GamaPoint) { yAxis.setRange(((GamaPoint) range).getX(), ((GamaPoint) range).getY()); } } if (expr2 != null) { Object range = expr2.value(scope); // Double range = Cast.asFloat(scope, expr.value(scope)); if (range instanceof Number) { double r = ((Number) range).doubleValue(); if (r > 0) { yAxis.setTickUnit(new NumberTickUnit(r)); } } } final CategoryAxis axis = plot.getDomainAxis(); Double gap = Cast.asFloat(scope, getFacetValue(scope, IKeyword.GAP, 0.01)); // ((BarRenderer) plot.getRenderer()).setItemMargin(gap); renderer.setMaximumBarWidth(1 - gap); axis.setCategoryMargin(gap); axis.setUpperMargin(gap); axis.setLowerMargin(gap); }
From source file:hudson.model.Job.java
public Graph getBuildTimeGraph() { return new Graph(getLastBuildTime(), 500, 400) { @Override// w ww.j a v a2s. co m protected JFreeChart createGraph() { class ChartLabel implements Comparable<ChartLabel> { final Run run; public ChartLabel(Run r) { this.run = r; } public int compareTo(ChartLabel that) { return this.run.number - that.run.number; } @Override public boolean equals(Object o) { // HUDSON-2682 workaround for Eclipse compilation bug // on (c instanceof ChartLabel) if (o == null || !ChartLabel.class.isAssignableFrom(o.getClass())) { return false; } ChartLabel that = (ChartLabel) o; return run == that.run; } public Color getColor() { // TODO: consider gradation. See // http://www.javadrive.jp/java2d/shape/index9.html Result r = run.getResult(); if (r == Result.FAILURE) return ColorPalette.RED; else if (r == Result.UNSTABLE) return ColorPalette.YELLOW; else if (r == Result.ABORTED || r == Result.NOT_BUILT) return ColorPalette.GREY; else return ColorPalette.BLUE; } @Override public int hashCode() { return run.hashCode(); } @Override public String toString() { String l = run.getDisplayName(); if (run instanceof Build) { String s = ((Build) run).getBuiltOnStr(); if (s != null) l += ' ' + s; } return l; } } DataSetBuilder<String, ChartLabel> data = new DataSetBuilder<String, ChartLabel>(); for (Run r : getNewBuilds()) { if (r.isBuilding()) continue; data.add(((double) r.getDuration()) / (1000 * 60), "min", new ChartLabel(r)); } final CategoryDataset dataset = data.build(); final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart // title null, // unused Messages.Job_minutes(), // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // urls ); 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()); StackedAreaRenderer ar = new StackedAreaRenderer2() { @Override public Paint getItemPaint(int row, int column) { ChartLabel key = (ChartLabel) dataset.getColumnKey(column); return key.getColor(); } @Override public String generateURL(CategoryDataset dataset, int row, int column) { ChartLabel label = (ChartLabel) dataset.getColumnKey(column); return String.valueOf(label.run.number); } @Override public String generateToolTip(CategoryDataset dataset, int row, int column) { ChartLabel label = (ChartLabel) dataset.getColumnKey(column); return label.run.getDisplayName() + " : " + label.run.getDurationString(); } }; plot.setRenderer(ar); // crop extra space around the graph plot.setInsets(new RectangleInsets(0, 0, 0, 5.0)); return chart; } }; }