Example usage for org.jfree.chart ChartFactory createStackedBarChart

List of usage examples for org.jfree.chart ChartFactory createStackedBarChart

Introduction

In this page you can find the example usage for org.jfree.chart ChartFactory createStackedBarChart.

Prototype

public static JFreeChart createStackedBarChart(String title, String domainAxisLabel, String rangeAxisLabel,
        CategoryDataset dataset) 

Source Link

Document

Creates a stacked bar chart with default settings.

Usage

From source file:be.pendragon.j2s.seventhcontinent.plot.jfreechart.JFreeChartPlotter.java

@Override
public void plot(Statistics[] stats, String[] seriesNames, String title, File outputFile) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int series = 0; series < stats.length; series++) {
        for (int pct = 1; pct <= 100; pct++) {
            double pctValue = stats[series].getPercentile(pct); // # of stars
            if (series > 0) {
                pctValue = pctValue - stats[series - 1].getPercentile(pct); // deltas are stackables
            }/*ww w . j a v a  2  s. c o  m*/
            dataset.addValue(pctValue, seriesNames[series], new Integer(pct));
        }
    }
    final JFreeChart barChart = ChartFactory.createStackedBarChart(title, "%", "# stars", dataset);
    try {
        ChartUtilities.saveChartAsJPEG(outputFile, barChart, width, height);
    } catch (IOException ex) {
        //      LOG.log(Level.SEVERE, "Plotting chart to file", ex);
        throw new RuntimeException("Plotting with JFreeChart chart to file", ex);
    }
}