Example usage for org.jfree.chart.renderer.category LayeredBarRenderer setItemMargin

List of usage examples for org.jfree.chart.renderer.category LayeredBarRenderer setItemMargin

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.category LayeredBarRenderer 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:org.jfree.chart.demo.LayeredBarChartDemo2.java

/**
 * Creates a new demo instance.//from w  w w .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:org.jfree.chart.demo.LayeredBarChartDemo1.java

/**
 * Creates a chart for the specified dataset.
 * /*from  ww  w. j  a va2  s  .com*/
 * @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:net.sf.dynamicreports.design.transformation.chartcustomizer.LayeredBarRendererCustomizer.java

@Override
public void customize(JFreeChart chart, ReportParameters reportParameters) {
    BarRenderer categoryRenderer = (BarRenderer) chart.getCategoryPlot().getRenderer();
    LayeredBarRenderer renderer = new LayeredBarRenderer();

    renderer.setBaseItemLabelsVisible(categoryRenderer.getBaseItemLabelsVisible());
    renderer.setBaseItemLabelFont(categoryRenderer.getBaseItemLabelFont());
    renderer.setBaseItemLabelPaint(categoryRenderer.getBaseItemLabelPaint());
    renderer.setBaseItemLabelGenerator(categoryRenderer.getBaseItemLabelGenerator());
    renderer.setShadowVisible(categoryRenderer.getShadowsVisible());
    CategoryDataset categoryDataset = chart.getCategoryPlot().getDataset();
    if (categoryDataset != null) {
        for (int i = 0; i < categoryDataset.getRowCount(); i++) {
            Paint seriesOutlinePaint = categoryRenderer.getSeriesOutlinePaint(i);
            if (seriesOutlinePaint != null) {
                renderer.setSeriesOutlinePaint(i, seriesOutlinePaint);
            }/* w w w  .ja va 2 s. c o  m*/
            Paint seriesPaint = categoryRenderer.getSeriesPaint(i);
            if (seriesPaint != null) {
                renderer.setSeriesPaint(i, seriesPaint);
            }
        }
    }
    renderer.setItemMargin(categoryRenderer.getItemMargin());
    GradientPaintTransformer gradientPaintTransformer = categoryRenderer.getGradientPaintTransformer();
    if (gradientPaintTransformer != null) {
        renderer.setGradientPaintTransformer(gradientPaintTransformer);
    }

    if (seriesBarWidths != null) {
        for (int i = 0; i < seriesBarWidths.size(); i++) {
            renderer.setSeriesBarWidth(i, seriesBarWidths.get(i));
        }
    }

    chart.getCategoryPlot().setRenderer(renderer);
}