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

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

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.category LayeredBarRenderer setSeriesBarWidth.

Prototype

public void setSeriesBarWidth(int series, double width) 

Source Link

Document

Sets the width of the bars of a series.

Usage

From source file:de.fub.maps.project.plugins.tasks.eval.heading.HeadingHistogrammContainer.java

public void setEvaluationItems(List<EvalutationItem> roadNetworkStatisticList) {
    headingHistogramm1.getDataset().removeAllSeries();
    int seriesIndex = 0;

    for (EvalutationItem item : roadNetworkStatisticList) {
        String name = item.getAggregator().getAggregatorDescriptor().getName();
        XYSeries series = new XYSeries(name);
        Set<Road> roads = item.getRoadNetworkProcess().getResult().getRoads();
        int[] historamm = new int[180];

        for (Road road : roads) {

            ILocation lastLocation = null;
            ILocation secondLastLocation = null;

            int i = 0;
            for (ILocation location : road.getNodes()) {

                if (lastLocation != null && secondLastLocation != null && i < historamm.length) {
                    double angleBetweenEdges = GPSCalc.getAngleBetweenEdges(lastLocation, secondLastLocation,
                            secondLastLocation, location);
                    int value = (int) angleBetweenEdges;
                    if (value < historamm.length) {
                        historamm[value]++;
                    }/*from  w w  w.  j a v a2 s. c o  m*/

                    i++;
                }

                lastLocation = secondLastLocation;
                secondLastLocation = location;
            }
        }

        for (int j = 0; j < historamm.length; j++) {
            series.add(j, historamm[j] == 0 ? null : historamm[j] / (double) historamm.length);
        }

        headingHistogramm1.getDataset().addSeries(series);

        XYItemRenderer renderer = headingHistogramm1.getBarChart().getXYPlot().getRenderer();
        if (renderer instanceof LayeredBarRenderer) {
            LayeredBarRenderer layeredBarRenderer = (LayeredBarRenderer) renderer;
            layeredBarRenderer.setSeriesBarWidth(seriesIndex,
                    1. / roadNetworkStatisticList.size() * (seriesIndex + 1));
        }
        seriesIndex++;
    }
}

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

/**
 * Creates a new demo instance.//from w  w w  . j a  va 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.
 * // w  ww  .  java  2s.  c o m
 * @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);
            }/*from  w  w w .  j a  va2 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);
}

From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java

private byte[] generateLayeredBarChart(CategoryDataset dataset, int width, int height) {
    JFreeChart chart = ChartFactory.createBarChart(null, // chart title
            null, // domain axis label
            null, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // the plot orientation
            true, // legend
            true, // tooltips
            false // urls
    );//ww w  .  jav  a 2 s.  co  m

    // set background
    chart.setBackgroundPaint(parseColor(statsManager.getChartBackgroundColor()));

    // set chart border
    chart.setPadding(new RectangleInsets(10, 5, 5, 5));
    chart.setBorderVisible(true);
    chart.setBorderPaint(parseColor("#cccccc"));

    // set anti alias
    chart.setAntiAlias(true);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    // disable bar outlines...
    LayeredBarRenderer renderer = new LayeredBarRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setSeriesBarWidth(0, .6);
    renderer.setSeriesBarWidth(1, .8);
    renderer.setSeriesBarWidth(2, 1.0);
    plot.setRenderer(renderer);

    // for this renderer, we need to draw the first series last...
    plot.setRowRenderingOrder(SortOrder.DESCENDING);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

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

    BufferedImage img = chart.createBufferedImage(width, height);
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        ImageIO.write(img, "png", out);
    } catch (IOException e) {
        log.warn("Error occurred while generating SiteStats chart image data", e);
    }
    return out.toByteArray();
}