Example usage for org.jfree.chart.axis CategoryAxis getCategoryMargin

List of usage examples for org.jfree.chart.axis CategoryAxis getCategoryMargin

Introduction

In this page you can find the example usage for org.jfree.chart.axis CategoryAxis getCategoryMargin.

Prototype

public double getCategoryMargin() 

Source Link

Document

Returns the category margin.

Usage

From source file:edu.ucla.stat.SOCR.chart.ChartGenerator_JTable.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);//from ww  w .  j  a va 2 s. c  o  m
        domainAxis.setUpperMargin(0.2);
        if (dataset.getColumnCount() == 1)
            renderer.setItemMargin(0.5);
        //   domainAxis.setCategoryMargin(domainAxis.getCategoryMargin()*2);

    }

    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);
    }

    return chart;
}