CategoryPlot categoryPlot = chart.getCategoryPlot(); BarRenderer br = (BarRenderer) categoryPlot.getRenderer(); br.setMaximumBarWidth(.35); // set maximum width to 35% of chart
/** * Returns a bar renderer. */ private BarRenderer getBarRenderer() { BarRenderer renderer = new BarRenderer(); renderer.setMaximumBarWidth( 0.07 ); for ( int i = 0; i < COLORS.length; i++ ) { renderer.setSeriesPaint( i, COLORS[i] ); renderer.setShadowVisible( false ); } return renderer; }
renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); renderer.setMaximumBarWidth(0.10);
@Override protected JFreeChart createGraph() { CategoryDataset dataset = createDataset(); JFreeChart chart = ChartFactory.createBarChart(graphTitle, "", "Number of failures", dataset, PlotOrientation.HORIZONTAL, false, false, false); NumberAxis domainAxis = new NumberAxis(); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); CategoryPlot plot = (CategoryPlot)chart.getPlot(); plot.setRangeAxis(domainAxis); BarRenderer renderer = (BarRenderer)plot.getRenderer(); renderer.setMaximumBarWidth(MAX_BAR_WIDTH); return chart; }
String fontName = "Lucida Sans"; JFreeChart chart = ChartFactory.createBarChart(null, "", "", dataset, PlotOrientation.VERTICAL, false, true, false ); StandardChartTheme theme = (StandardChartTheme)org.jfree.chart.StandardChartTheme.createJFreeTheme(); theme.setTitlePaint( Color.decode( "#4572a7" ) ); theme.setExtraLargeFont( new Font(fontName,Font.PLAIN, 16) ); //title theme.setLargeFont( new Font(fontName,Font.BOLD, 15)); //axis-title theme.setRegularFont( new Font(fontName,Font.PLAIN, 11)); theme.setRangeGridlinePaint( Color.decode("#C0C0C0")); theme.setPlotBackgroundPaint( Color.white ); theme.setChartBackgroundPaint( Color.white ); theme.setGridBandPaint( Color.red ); theme.setAxisOffset( new RectangleInsets(0,0,0,0) ); theme.setBarPainter(new StandardBarPainter()); theme.setAxisLabelPaint( Color.decode("#666666") ); theme.apply( chart ); chart.getCategoryPlot().setOutlineVisible( false ); chart.getCategoryPlot().getRangeAxis().setAxisLineVisible( false ); chart.getCategoryPlot().getRangeAxis().setTickMarksVisible( false ); chart.getCategoryPlot().setRangeGridlineStroke( new BasicStroke() ); chart.getCategoryPlot().getRangeAxis().setTickLabelPaint( Color.decode("#666666") ); chart.getCategoryPlot().getDomainAxis().setTickLabelPaint( Color.decode("#666666") ); chart.setTextAntiAlias( true ); chart.setAntiAlias( true ); chart.getCategoryPlot().getRenderer().setSeriesPaint( 0, Color.decode( "#4572a7" )); BarRenderer rend = (BarRenderer) chart.getCategoryPlot().getRenderer(); rend.setShadowVisible( true ); rend.setShadowXOffset( 2 ); rend.setShadowYOffset( 0 ); rend.setShadowPaint( Color.decode( "#C0C0C0")); rend.setMaximumBarWidth( 0.1);
public static JFreeChart doCreateSummarizerChart(CategoryDataset dataset, String yAxis, String chartTitle) { final JFreeChart chart = ChartFactory.createBarChart(chartTitle, // chart // title null, // unused yAxis, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips true // urls ); chart.setBackgroundPaint(Color.WHITE); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.BLACK); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); renderer.setBaseStroke(new BasicStroke(4.0f)); renderer.setItemMargin(0); renderer.setMaximumBarWidth(0.05); return chart; }
/** * Utility method to set the default style of the Bar Charts * * @param chart {@link JFreeChart} to style */ private static void setBarChartDefaults(JFreeChart chart) { ChartUtil.setDefaults(chart); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setAxisOffset(new RectangleInsets(1.0, 1.0, 1.0, 1.0)); // renderer BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setBaseItemLabelFont(ChartDefaults.defaultFont); renderer.setBaseItemLabelsVisible(false); renderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER)); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setBaseItemLabelPaint(ChartDefaults.axisLabelColor); StandardCategoryToolTipGenerator generator = new StandardCategoryToolTipGenerator("{1}, {2}", NumberFormat.getInstance()); renderer.setBaseToolTipGenerator(generator); renderer.setDrawBarOutline(false); renderer.setMaximumBarWidth(0.1); renderer.setItemMargin(0.02f); for (int j = 0; j < ChartDefaults.darkColors.length; j++) { renderer.setSeriesPaint(j, ChartDefaults.darkColors[j]); } }
renderer.setMaximumBarWidth( chartDefinition.getMaxBarWidth().doubleValue() );
barRenderer.setMaximumBarWidth( chartDefinition.getMaxBarWidth().doubleValue() );