Example usage for org.jfree.chart.renderer BarRenderer setItemMargin

List of usage examples for org.jfree.chart.renderer BarRenderer setItemMargin

Introduction

In this page you can find the example usage for org.jfree.chart.renderer BarRenderer setItemMargin.

Prototype

public void setItemMargin(double percent) 

Source Link

Document

Sets the item margin and sends a RendererChangeEvent to all registered listeners.

Usage

From source file:hr.restart.util.chart.ChartXYZ.java

/**
  * Creates a BAR CHART./* www  .j a  v a2 s.  com*/
  * 
  * @param dataset The org.jfree.data.CategoryDataset
  * @param title The title
  * @return org.jfree.chart.JFreeChart
  */
final private JFreeChart createBarChart(final CategoryDataset dataset, String title) {

    final JFreeChart chart = ChartFactory.createBarChart(title, // chart title
            "", // domain axis label
            "", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // the plot orientation
            true, // include legend
            true, false);

    chart.setBackgroundPaint(Color.white);

    //print the subtitles
    java.util.List subs = getSubtitles();
    if (subs != null) {
        for (int i = 0; i < subs.size(); i++) {
            chart.addSubtitle(new TextTitle(subs.get(i).toString()));
        }
    }

    //      NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    //plot.setBackgroundPaint(Color.lightGray);
    //plot.setDomainGridlinePaint(Color.white);
    //plot.setRangeGridlinePaint(Color.white);

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setItemMargin(getItemMargin());
    adjustBarRenderer(renderer);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryMargin(getCategoryMargin());
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}