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

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

Introduction

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

Prototype

public void setLowerMargin(double margin) 

Source Link

Document

Sets the lower margin for the axis and sends an AxisChangeEvent to all registered listeners.

Usage

From source file:edu.ucla.stat.SOCR.chart.demo.StackedAreaChartDemo.java

/**
 * Creates a sample chart.//from   w  ww. j av  a  2s.c  om
 * 
 * @param dataset  the dataset.
 * 
 * @return A sample chart.
 */
protected JFreeChart createChart(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createStackedAreaChart(chartTitle, // chart title
            domainLabel, // domain axis label
            rangeLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            !legendPanelOn, // include legend
            true, false);

    chart.setBackgroundPaint(Color.white);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setForegroundAlpha(0.85f);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setBaseItemLabelsVisible(true);
    AreaRenderer renderer2 = (AreaRenderer) plot.getRenderer();
    renderer2.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());

    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);/*w  w  w . jav  a 2s.  c om*/
    // 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:playground.dgrether.analysis.charts.DgDefaultAxisBuilder.java

public CategoryAxis createCategoryAxis(String xLabel) {
    CategoryAxis categoryAxis = new CategoryAxis(xLabel);
    categoryAxis.setCategoryMargin(0.05); // percentage of space between categories
    categoryAxis.setLowerMargin(0.01); // percentage of space before first bar
    categoryAxis.setUpperMargin(0.01); // percentage of space after last bar
    categoryAxis.setLabelFont(labelFont);
    categoryAxis.setTickLabelFont(axisFont);
    return categoryAxis;
}

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);
    axis.setCategoryMargin(CATEGORY_MARGIN);
    axis.setUpperMargin(UPPER_MARGIN);//from   www . ja v  a  2  s  . com
}

From source file:org.jfree.chart.demo.ParetoChartDemo.java

/**
 * Creates a new demo instance.//from w w  w  . java  2 s  .com
 *
 * @param title  the frame title.
 */
public ParetoChartDemo(final String title) {

    super(title);

    final DefaultKeyedValues data = new DefaultKeyedValues();
    data.addValue("C", new Integer(4843));
    data.addValue("C++", new Integer(2098));
    data.addValue("C#", new Integer(26));
    data.addValue("Java", new Integer(1901));
    data.addValue("Perl", new Integer(2507));
    data.addValue("PHP", new Integer(1689));
    data.addValue("Python", new Integer(948));
    data.addValue("Ruby", new Integer(100));
    data.addValue("SQL", new Integer(263));
    data.addValue("Unix Shell", new Integer(485));

    data.sortByValues(SortOrder.DESCENDING);
    final KeyedValues cumulative = DataUtilities.getCumulativePercentages(data);
    final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Languages", data);

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Freshmeat Software Projects", // chart title
            "Language", // domain axis label
            "Projects", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, false);

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.addSubtitle(new TextTitle("By Programming Language"));
    chart.addSubtitle(new TextTitle("As at 5 March 2003"));

    // set the background color for the chart...
    chart.setBackgroundPaint(new Color(0xBBBBDD));

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLowerMargin(0.02);
    domainAxis.setUpperMargin(0.02);

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

    final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();

    final CategoryDataset dataset2 = DatasetUtilities.createCategoryDataset("Cumulative", cumulative);
    final NumberAxis axis2 = new NumberAxis("Percent");
    axis2.setNumberFormatOverride(NumberFormat.getPercentInstance());
    plot.setRangeAxis(1, axis2);
    plot.setDataset(1, dataset2);
    plot.setRenderer(1, renderer2);
    plot.mapDatasetToRangeAxis(1, 1);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
    // OPTIONAL CUSTOMISATION COMPLETED.

    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(550, 270));
    setContentPane(chartPanel);

}

From source file:com.kiyoshi.gui.AreaChart.java

private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createAreaChart("Area Chart", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );//  ww  w . ja v a  2  s  .  c  o  m

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    // set the background color for the chart...
    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setAnchor(StandardLegend.SOUTH);
    chart.setBackgroundPaint(Color.white);
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setForegroundAlpha(0.5f);

    //      plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 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);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.addCategoryLabelToolTip("Type 1", "The first type.");
    domainAxis.addCategoryLabelToolTip("Type 2", "The second type.");
    domainAxis.addCategoryLabelToolTip("Type 3", "The third type.");

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLabelAngle(0 * Math.PI / 2.0);
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.others.CumulativeCurveChart.java

public JFreeChart createChart(DatasetMap datasetMap) {
    CategoryDataset datasetValue = (CategoryDataset) datasetMap.getDatasets().get("1");
    CategoryDataset datasetCumulative = (CategoryDataset) datasetMap.getDatasets().get("2");

    JFreeChart chart = ChartFactory.createBarChart(name, // chart title
            xLabel, // domain axis label
            yLabel, // range axis label
            datasetValue, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, false);/*ww w  .ja v a 2 s .c o m*/

    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLowerMargin(0.02);
    domainAxis.setUpperMargin(0.02);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();

    NumberAxis axis2 = new NumberAxis("Percent");
    axis2.setNumberFormatOverride(NumberFormat.getPercentInstance());
    plot.setRangeAxis(1, axis2);
    plot.setDataset(1, datasetCumulative);
    plot.setRenderer(1, renderer2);
    plot.mapDatasetToRangeAxis(1, 1);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    return chart;
}

From source file:com.mergano.core.AreaChart.java

private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createAreaChart("Order statistic", // chart title
            "Days", // domain axis label
            "Order Average", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            false, // tooltips
            false // urls
    );/*  w ww  .  jav a 2  s . c  om*/

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    // set the background color for the chart...
    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setAnchor(StandardLegend.SOUTH);
    chart.setBackgroundPaint(Color.white);
    chart.setAntiAlias(true);

    CategoryPlot plot = chart.getCategoryPlot();
    plot.getRenderer().setSeriesPaint(0, new Color(0, 191, 165));
    plot.setForegroundAlpha(0.75f);
    plot.setBackgroundPaint(Color.white);

    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); // disable this
    plot.setDomainGridlinesVisible(false);
    plot.setDomainGridlinePaint(new Color(240, 240, 240));
    plot.setRangeGridlinesVisible(false);
    plot.setRangeGridlinePaint(new Color(240, 240, 240));
    plot.setDomainCrosshairPaint(Color.MAGENTA);
    plot.setRangeCrosshairPaint(Color.CYAN);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.addCategoryLabelToolTip("Type 1", "The first type.");
    domainAxis.addCategoryLabelToolTip("Type 2", "The second type.");
    domainAxis.addCategoryLabelToolTip("Type 3", "The third type.");

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLabelAngle(0 * Math.PI / 2.0);
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:org.jfree.chart.demo.LayeredBarChartDemo2.java

/**
 * Creates a new demo instance.//from  www.  java 2 s.  c o m
 *
 * @param title  the frame title.
 */
public LayeredBarChartDemo2(final String title) {

    super(title);

    // create a dataset...
    final double[][] data = new double[][] { { 41.0, 33.0, 22.0, 64.0, 42.0, 62.0, 22.0, 14.0 },
            { 55.0, 63.0, 55.0, 48.0, 54.0, 37.0, 41.0, 39.0 },
            { 57.0, 75.0, 43.0, 33.0, 63.0, 46.0, 57.0, 33.0 } };

    final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Series ", "Factor ", data);

    // create the chart...
    final CategoryAxis categoryAxis = new CategoryAxis("Category");
    final ValueAxis valueAxis = new NumberAxis("Score (%)");

    final CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, new LayeredBarRenderer());

    plot.setOrientation(PlotOrientation.VERTICAL);
    final JFreeChart chart = new JFreeChart("Layered Bar Chart Demo 2", 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.5);

    renderer.setItemMargin(0.01);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryMargin(0.25);
    domainAxis.setUpperMargin(0.05);
    domainAxis.setLowerMargin(0.05);

    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

From source file:edu.ucla.stat.SOCR.chart.demo.StatisticalLineChartDemo1.java

/**
 * Creates a sample chart.//ww w  . j a v  a2s.  c  o  m
 * 
 * @param dataset  a dataset.
 * 
 * @return The chart.
 */
protected JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createLineChart(chartTitle, // chart title
            domainLabel, // domain axis label
            rangeLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            !legendPanelOn, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setUpperMargin(0.0);
    domainAxis.setLowerMargin(0.0);

    // customise the range axis...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(true);

    // customise the renderer...
    StatisticalLineAndShapeRenderer renderer = new StatisticalLineAndShapeRenderer(true, false);
    plot.setRenderer(renderer);

    // OPTIONAL CUSTOMISATION COMPLETED.
    return chart;
}