List of usage examples for org.jfree.chart.axis CategoryAxis setCategoryMargin
public void setCategoryMargin(double margin)
From source file:org.jfree.chart.demo.LayeredBarChartDemo1.java
/** * Creates a chart for the specified dataset. * /*from w w w. j a v a 2 s . c o m*/ * @param dataset the dataset. * * @return a chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final CategoryAxis categoryAxis = new CategoryAxis("Category"); //categoryAxis.setMaxCategoryLabelWidthRatio(10.0f); final ValueAxis valueAxis = new NumberAxis("Score (%)"); final CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, new LayeredBarRenderer()); plot.setOrientation(PlotOrientation.HORIZONTAL); final JFreeChart chart = new JFreeChart("Layered Bar Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, true); // set the background color for the chart... chart.setBackgroundPaint(Color.lightGray); final LayeredBarRenderer renderer = (LayeredBarRenderer) plot.getRenderer(); // we can set each series bar width individually or let the renderer manage a standard view. // the width is set in percentage, where 1.0 is the maximum (100%). renderer.setSeriesBarWidth(0, 1.0); renderer.setSeriesBarWidth(1, 0.7); renderer.setSeriesBarWidth(2, 0.4); renderer.setItemMargin(0.01); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryMargin(0.25); domainAxis.setUpperMargin(0.05); domainAxis.setLowerMargin(0.05); return chart; }
From source file:org.perfrepo.web.controller.reports.testgroup.TestGroupChartBean.java
public void drawChart(OutputStream out, Object data) throws IOException { if (data instanceof ChartData) { ChartData chartData = (ChartData) data; JFreeChart chart = ChartFactory.createBarChart(chartData.getTitle(), "Test", "%", processDataSet(chartData), PlotOrientation.HORIZONTAL, false, true, false); chart.addSubtitle(new TextTitle("Comparison", new Font("Dialog", Font.ITALIC, 10))); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); CustomRenderer renderer = new CustomRenderer(); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); renderer.setBaseItemLabelGenerator( new StandardCategoryItemLabelGenerator("{2}%", NumberFormat.getInstance())); renderer.setBaseItemLabelsVisible(true); renderer.setDrawBarOutline(false); renderer.setMaximumBarWidth(1d / (chartData.getTests().length + 4.0)); plot.setRenderer(renderer);/*from w ww . ja v a 2 s. c o m*/ CategoryAxis categoryAxis = plot.getDomainAxis(); categoryAxis.setCategoryMargin(0.1); categoryAxis.setUpperMargin(0.1); categoryAxis.setLowerMargin(0.1); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperMargin(0.10); BufferedImage buffImg = chart.createBufferedImage(640, chartData.getTests().length * 100 + 100); ImageIO.write(buffImg, "gif", out); } }
From source file:org.operamasks.faces.render.graph.CurveAreaChartRenderer.java
private JFreeChart createCurveAreaChart(CategoryDataset dataset, PlotOrientation orientation) { CategoryAxis xAxis = new CategoryAxis(); xAxis.setLowerMargin(0.0);//from ww w .j a v a 2s . c o m xAxis.setUpperMargin(0.0); xAxis.setCategoryMargin(0.0); NumberAxis yAxis = new NumberAxis(); yAxis.setAutoRangeIncludesZero(false); CurveAndShapeRenderer renderer = new CurveAndShapeRenderer(true, false); renderer.setDrawArea(true); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(orientation); if (dataset.getRowCount() > 1) { plot.setForegroundAlpha(0.75f); } return new JFreeChart(null, null, plot, false); }
From source file:org.matsim.counts.algorithms.graphs.CountsLoadCurveGraph.java
@Override public JFreeChart createChart(final int nbr) { String title = this.getChartTitle() + ", Iteration: " + this.iteration_; this.chart_ = ChartFactory.createBarChart(title, "Hour", "Volumes [veh/h]", this.dataset0, PlotOrientation.VERTICAL, true, // legend? true, // tooltips? false // URLs? );//from w w w .j a v a 2 s .c o m CategoryPlot plot = this.chart_.getCategoryPlot(); // plot.getRangeAxis().setRange(0.0, 10000.0); // do not set a fixed range for the single link graphs plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); // BarRenderer renderer=(BarRenderer) plot.getRenderer(); BarRenderer renderer = new BarRenderer(); renderer.setSeriesOutlinePaint(0, Color.black); renderer.setSeriesOutlinePaint(1, Color.black); renderer.setSeriesPaint(0, Color.getHSBColor((float) 0.62, (float) 0.56, (float) 0.93)); // Color.orange gives a dirty yellow! renderer.setSeriesPaint(1, Color.getHSBColor((float) 0.1, (float) 0.79, (float) 0.89)); renderer.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator()); renderer.setSeriesToolTipGenerator(1, new StandardCategoryToolTipGenerator()); renderer.setItemMargin(0.0); // configure plot with light colors instead of the default 3D renderer.setShadowVisible(false); renderer.setBarPainter(new StandardBarPainter()); this.chart_.setBackgroundPaint(Color.getHSBColor((float) 0.0, (float) 0.0, (float) 0.93)); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.gray); plot.setRangeGridlinesVisible(true); plot.setRenderer(0, renderer); plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); // TRRE: plot.setDataset(1, this.dataset1); plot.mapDatasetToRangeAxis(1, 1); final CategoryAxis axis1 = plot.getDomainAxis(); axis1.setCategoryMargin(0.25); // leave a gap of 25% between categories /* TRRE: final ValueAxis axis2 = new NumberAxis("Signed Rel. Error [%]"); plot.setRangeAxis(1, axis2); final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); renderer2.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator()); renderer2.setSeriesShape(0, new Rectangle2D.Double(-1.5, -1.5, 3.0, 3.0)); renderer2.setSeriesPaint(0, Color.black); renderer2.setBaseStroke(new BasicStroke(2.5f)); plot.setRenderer(1, renderer2); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); */ return this.chart_; }
From source file:com.sonyericsson.jenkins.plugins.bfa.graphs.StackedBarChart.java
@Override protected JFreeChart createGraph() { DefaultCategoryDataset dataset = createDataset(); JFreeChart chart = ChartFactory.createStackedBarChart(getTitle(), getXAxisTitle(), getYAxisTitle(), dataset, PlotOrientation.VERTICAL, true, true, false); final CategoryPlot plot = chart.getCategoryPlot(); int index = dataset.getRowIndex(NO_FAILURE); if (index >= 0) { plot.getRenderer().setSeriesVisibleInLegend(index, false); }//w w w . ja va 2 s. c om CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setCategoryMargin(0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return chart; }
From source file:org.codehaus.mojo.dashboard.report.plugin.chart.BarChartRenderer.java
public void createChart() { CategoryDataset categorydataset = (CategoryDataset) this.datasetStrategy.getDataset(); report = ChartFactory.createBarChart(this.datasetStrategy.getTitle(), this.datasetStrategy.getYAxisLabel(), this.datasetStrategy.getXAxisLabel(), categorydataset, PlotOrientation.HORIZONTAL, true, true, false);/* www . jav a 2 s . com*/ // report.setBackgroundPaint( Color.lightGray ); report.setPadding(new RectangleInsets(5.0d, 5.0d, 5.0d, 5.0d)); CategoryPlot categoryplot = (CategoryPlot) report.getPlot(); categoryplot.setBackgroundPaint(Color.white); categoryplot.setRangeGridlinePaint(Color.lightGray); categoryplot.setDomainGridlinePaint(Color.lightGray); categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); if (datasetStrategy instanceof CoberturaBarChartStrategy || datasetStrategy instanceof CloverBarChartStrategy || datasetStrategy instanceof MultiCloverBarChartStrategy) { numberaxis.setRange(0.0D, BarChartRenderer.NUMBER_AXIS_RANGE); numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance()); } else { numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } numberaxis.setLowerMargin(0.0D); CategoryAxis axis = categoryplot.getDomainAxis(); axis.setLowerMargin(0.02); // two percent axis.setCategoryMargin(0.10); // ten percent axis.setUpperMargin(0.02); // two percent BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setItemMargin(0.10); barrenderer.setDrawBarOutline(false); barrenderer.setBaseItemLabelsVisible(true); if (datasetStrategy instanceof CoberturaBarChartStrategy || datasetStrategy instanceof CloverBarChartStrategy || datasetStrategy instanceof MultiCloverBarChartStrategy) { barrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", NumberFormat.getPercentInstance(Locale.getDefault()))); } else { barrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); } int height = (categorydataset.getColumnCount() * ChartUtils.STANDARD_BARCHART_ENTRY_HEIGHT * categorydataset.getRowCount()); if (height > ChartUtils.MINIMUM_HEIGHT) { super.setHeight(height); } else { super.setHeight(ChartUtils.MINIMUM_HEIGHT); } Paint[] paints = this.datasetStrategy.getPaintColor(); for (int i = 0; i < categorydataset.getRowCount() && i < paints.length; i++) { barrenderer.setSeriesPaint(i, paints[i]); } }
From source file:gov.nih.nci.caintegrator.application.geneexpression.GeneExpressionPlotServiceImpl.java
private void customizeAxisMargin(JFreeChart chart) { CategoryAxis axis = chart.getCategoryPlot().getDomainAxis(); axis.setLowerMargin(LOWER_MARGIN);/* w w w .j a v a 2s. c om*/ axis.setCategoryMargin(CATEGORY_MARGIN); axis.setUpperMargin(UPPER_MARGIN); }
From source file:org.matsim.counts.algorithms.graphs.CountsGEHCurveGraph.java
@Override public JFreeChart createChart(final int nbr) { String title = this.getChartTitle() + ", Iteration: " + this.iteration_; this.chart_ = ChartFactory.createBarChart(title, "Hour", "GEH", this.dataset, PlotOrientation.VERTICAL, false, // legend? false, // tooltips? false // URLs? );/*from w w w . j av a 2 s .com*/ CategoryPlot plot = this.chart_.getCategoryPlot(); // plot.getRangeAxis().setRange(0.0, 10000.0); // do not set a fixed range for the single link graphs plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); // BarRenderer renderer=(BarRenderer) plot.getRenderer(); // BarRenderer renderer = new BarRenderer(); /* * Chooses the color adaptive based on the value to be shown by a bar. * Values <= 5.0 are green, values >= 10 are red. In between the color is interpolated. */ BarRenderer renderer = new BarRenderer() { @Override public Paint getItemPaint(final int row, final int column) { double value = dataset.getValue(row, column).doubleValue(); if (value <= 5.0) return Color.green; else if (value >= 10) return Color.red; else { if (value < 7.5) { int mixed = mix(Color.yellow.getRGB(), Color.green.getRGB(), (7.5 - value) / 2.5); return new Color(mixed); } else { int mixed = mix(Color.red.getRGB(), Color.yellow.getRGB(), (10.0 - value) / 2.5); return new Color(mixed); } } // if (value <= 5.0) return Color.green; // else if (value >= 10) return Color.red; // else { // int mixed = mix(Color.red.getRGB(), Color.green.getRGB(), (10.0 - value) / 5.0); // return new Color(mixed); // } } }; renderer.setSeriesOutlinePaint(0, Color.black); renderer.setSeriesPaint(0, Color.getHSBColor((float) 0.62, (float) 0.56, (float) 0.93)); renderer.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator()); renderer.setItemMargin(0.0); // configure plot with light colors instead of the default 3D renderer.setShadowVisible(false); renderer.setBarPainter(new StandardBarPainter()); this.chart_.setBackgroundPaint(Color.getHSBColor((float) 0.0, (float) 0.0, (float) 0.93)); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.gray); plot.setRangeGridlinesVisible(true); plot.setRenderer(0, renderer); plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); plot.mapDatasetToRangeAxis(1, 1); final CategoryAxis axis1 = plot.getDomainAxis(); axis1.setCategoryMargin(0.25); // leave a gap of 25% between categories return this.chart_; }
From source file:com.intel.stl.ui.common.view.ComponentFactory.java
public static JFreeChart createBarChart(String xAxisLabel, String yAxisLabel, CategoryDataset dataset) { if (dataset == null) { throw new IllegalArgumentException("No dataset."); }//from w ww . j a v a2 s .c o m JFreeChart jfreechart = ChartFactory.createBarChart(null, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot categoryplot = jfreechart.getCategoryPlot(); categoryplot.setBackgroundPaint(null); categoryplot.setOutlinePaint(null); categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); categoryplot.setRangePannable(true); categoryplot.setRangeGridlinePaint(UIConstants.INTEL_DARK_GRAY); categoryplot.getRangeAxis().setLabelFont(UIConstants.H5_FONT); categoryplot.getDomainAxis().setLabelFont(UIConstants.H5_FONT); BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setBarPainter(new StandardBarPainter()); barrenderer.setBaseItemLabelsVisible(true); barrenderer.setShadowVisible(false); barrenderer.setSeriesPaint(0, UIConstants.INTEL_BLUE); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setCategoryMargin(0.02D); categoryaxis.setUpperMargin(0.01D); categoryaxis.setLowerMargin(0.01D); // categoryaxis.setAxisLineVisible(false); categoryaxis.setMaximumCategoryLabelWidthRatio(0.95F); NumberAxis axis = (NumberAxis) categoryplot.getRangeAxis(); axis.setRangeType(RangeType.POSITIVE); return jfreechart; }
From source file:com.intel.stl.ui.common.view.ComponentFactory.java
public static JFreeChart createTopNBarChart(String yAxisLabel, CategoryDataset dataset) { JFreeChart jfreechart = ChartFactory.createBarChart(null, null, yAxisLabel, dataset, PlotOrientation.HORIZONTAL, true, true, false); CategoryPlot categoryplot = jfreechart.getCategoryPlot(); categoryplot.setBackgroundPaint(null); categoryplot.setOutlinePaint(null);// w w w. ja v a2 s .c o m categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); categoryplot.setRangePannable(true); categoryplot.setRangeGridlinesVisible(true); categoryplot.setRangeGridlinePaint(UIConstants.INTEL_DARK_GRAY); BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setBarPainter(new StandardBarPainter()); barrenderer.setShadowVisible(false); barrenderer.setItemMargin(0.015); barrenderer.setSeriesPaint(0, UIConstants.INTEL_BLUE); barrenderer.setSeriesPaint(1, UIConstants.INTEL_LIGHT_BLUE); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setCategoryMargin(0.15D); categoryaxis.setUpperMargin(0.02D); categoryaxis.setLowerMargin(0.02D); categoryaxis.setMaximumCategoryLabelWidthRatio(0.5F); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setRangeType(RangeType.POSITIVE); numberaxis.setStandardTickUnits(createLargeNumberTickUnits()); numberaxis.setUpperMargin(0.20000000000000001D); numberaxis.setLabelFont(UIConstants.H5_FONT); numberaxis.setLabelInsets(new RectangleInsets(0, 0, 0, 0)); numberaxis.setTickMarksVisible(true); numberaxis.setTickLabelsVisible(true); LegendTitle legend = jfreechart.getLegend(); legend.setFrame(BlockBorder.NONE); legend.setItemFont(barrenderer.getBaseItemLabelFont().deriveFont(10.0f)); return jfreechart; }