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, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) 

Source Link

Document

Creates a stacked bar chart with default settings.

Usage

From source file:com.griddynamics.jagger.reporting.chart.ChartHelper.java

public static JFreeChart createStackedBarChart(String title, List<List<Double>> bars, List<String> zoneLabels,
        String xLabel, String yLabel, ColorTheme theme) {
    DefaultCategoryDataset ds = new DefaultCategoryDataset();

    Integer barId = 0;/*from w w  w.j a  v a  2  s .  c om*/
    int maxStack = 0;
    for (List<Double> bar : bars) {
        int i = 0;
        maxStack = Math.max(maxStack, bar.size());
        for (double value : bar) {
            ds.addValue(value, zoneLabels.get(i), barId);
            i++;
        }
        barId++;
    }

    JFreeChart chart = ChartFactory.createStackedBarChart(title, xLabel, yLabel, ds, PlotOrientation.VERTICAL,
            true, false, false);

    formatColorTheme(chart, theme);
    formatBars(chart);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.getDomainAxis().setCategoryMargin(0);
    plot.getDomainAxis().setLowerMargin(0);
    plot.getDomainAxis().setUpperMargin(0);

    Color[] colors = generateJetSpectrum(maxStack);
    for (int i = 0; i < maxStack; i++) {
        plot.getRenderer().setSeriesPaint(i, colors[i]);
        plot.getRenderer().setSeriesOutlinePaint(i, Color.white);
    }

    return chart;
}

From source file:org.altaprise.vawr.charts.demos.StackedBarChartDemo4.java

/**
 * Creates a sample chart./* w  w  w.j  a v  a  2  s  . c o m*/
 * 
 * @param dataset  the dataset for the chart.
 * 
 * @return A sample chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createStackedBarChart("Stacked Bar Chart Demo 4", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // the plot orientation
            true, // legend
            true, // tooltips
            false // urls
    );

    GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
    KeyToGroupMap map = new KeyToGroupMap("G1");
    map.mapKeyToGroup("Product 1 (US)", "G1");
    map.mapKeyToGroup("Product 1 (Europe)", "G1");
    map.mapKeyToGroup("Product 1 (Asia)", "G1");
    map.mapKeyToGroup("Product 1 (Middle East)", "G1");
    map.mapKeyToGroup("Product 2 (US)", "G2");
    map.mapKeyToGroup("Product 2 (Europe)", "G2");
    map.mapKeyToGroup("Product 2 (Asia)", "G2");
    map.mapKeyToGroup("Product 2 (Middle East)", "G2");
    map.mapKeyToGroup("Product 3 (US)", "G3");
    map.mapKeyToGroup("Product 3 (Europe)", "G3");
    map.mapKeyToGroup("Product 3 (Asia)", "G3");
    map.mapKeyToGroup("Product 3 (Middle East)", "G3");
    renderer.setSeriesToGroupMap(map);

    renderer.setItemMargin(0.0);
    Paint p1 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0x22, 0xFF), 0.0f, 0.0f,
            new Color(0x88, 0x88, 0xFF));
    renderer.setSeriesPaint(0, p1);
    renderer.setSeriesPaint(4, p1);
    renderer.setSeriesPaint(8, p1);

    Paint p2 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0xFF, 0x22), 0.0f, 0.0f,
            new Color(0x88, 0xFF, 0x88));
    renderer.setSeriesPaint(1, p2);
    renderer.setSeriesPaint(5, p2);
    renderer.setSeriesPaint(9, p2);

    Paint p3 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0x22, 0x22), 0.0f, 0.0f,
            new Color(0xFF, 0x88, 0x88));
    renderer.setSeriesPaint(2, p3);
    renderer.setSeriesPaint(6, p3);
    renderer.setSeriesPaint(10, p3);

    Paint p4 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0xFF, 0x22), 0.0f, 0.0f,
            new Color(0xFF, 0xFF, 0x88));
    renderer.setSeriesPaint(3, p4);
    renderer.setSeriesPaint(7, p4);
    renderer.setSeriesPaint(11, p4);
    renderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));

    SubCategoryAxis domainAxis = new SubCategoryAxis("Product / Month");
    domainAxis.setCategoryMargin(0.05);
    domainAxis.addSubCategory("Product 1");
    domainAxis.addSubCategory("Product 2");
    domainAxis.addSubCategory("Product 3");

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setDomainAxis(domainAxis);
    //plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
    plot.setRenderer(renderer);
    plot.setFixedLegendItems(createLegendItems());
    return chart;

}

From source file:de.laures.cewolf.taglib.CewolfChartFactory.java

public static JFreeChart getChartInstance(String chartType, String title, String xAxisLabel, String yAxisLabel,
        Dataset data) throws ChartValidationException {
    // first check the dynamically registered chart types
    CewolfChartFactory factory = (CewolfChartFactory) factories.get(chartType);
    if (factory != null) {
        // custom factory found, use it
        return factory.getChartInstance(title, xAxisLabel, yAxisLabel, data);
    }//from w ww.j av a 2  s  . com

    switch (getChartTypeConstant(chartType)) {
    case XY:
        check(data, XYDataset.class, chartType);
        return ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, (XYDataset) data,
                PlotOrientation.VERTICAL, true, true, true);
    case PIE:
        check(data, PieDataset.class, chartType);
        return ChartFactory.createPieChart(title, (PieDataset) data, true, true, true);
    case AREA_XY:
        check(data, XYDataset.class, chartType);
        return ChartFactory.createXYAreaChart(title, xAxisLabel, yAxisLabel, (XYDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case SCATTER:
        check(data, XYDataset.class, chartType);
        return ChartFactory.createScatterPlot(title, xAxisLabel, yAxisLabel, (XYDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case AREA:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createAreaChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case HORIZONTAL_BAR:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.HORIZONTAL, true, false, false);
    case HORIZONTAL_BAR_3D:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createBarChart3D(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.HORIZONTAL, true, false, false);
    case LINE:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createLineChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case STACKED_HORIZONTAL_BAR:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createStackedBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.HORIZONTAL, true, false, false);
    case STACKED_VERTICAL_BAR:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createStackedBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case STACKED_VERTICAL_BAR_3D:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createStackedBarChart3D(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case VERTICAL_BAR:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case VERTICAL_BAR_3D:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createBarChart3D(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case TIME_SERIES:
        check(data, XYDataset.class, chartType);
        return ChartFactory.createTimeSeriesChart(title, xAxisLabel, yAxisLabel, (XYDataset) data, true, false,
                false);
    case CANDLE_STICK:
        check(data, OHLCDataset.class, chartType);
        return ChartFactory.createCandlestickChart(title, xAxisLabel, yAxisLabel, (OHLCDataset) data, true);
    case HIGH_LOW:
        check(data, OHLCDataset.class, chartType);
        return ChartFactory.createHighLowChart(title, xAxisLabel, yAxisLabel, (OHLCDataset) data, true);
    case GANTT:
        check(data, IntervalCategoryDataset.class, chartType);
        return ChartFactory.createGanttChart(title, xAxisLabel, yAxisLabel, (IntervalCategoryDataset) data,
                true, false, false);
    case WIND:
        check(data, WindDataset.class, chartType);
        return ChartFactory.createWindPlot(title, xAxisLabel, yAxisLabel, (WindDataset) data, true, false,
                false);
    //case SIGNAL :
    //  check(data, SignalsDataset.class, chartType);
    //  return ChartFactory.createSignalChart(title, xAxisLabel, yAxisLabel, (SignalsDataset) data, true);
    case VERRTICAL_XY_BAR:
        check(data, IntervalXYDataset.class, chartType);
        return ChartFactory.createXYBarChart(title, xAxisLabel, true, yAxisLabel, (IntervalXYDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case PIE_3D:
        check(data, PieDataset.class, chartType);
        return ChartFactory.createPieChart3D(title, (PieDataset) data, true, false, false);
    case METER:
        check(data, ValueDataset.class, chartType);
        MeterPlot plot = new MeterPlot((ValueDataset) data);
        JFreeChart chart = new JFreeChart(title, plot);
        return chart;
    case STACKED_AREA:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createStackedAreaChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case BUBBLE:
        check(data, XYZDataset.class, chartType);
        return ChartFactory.createBubbleChart(title, xAxisLabel, yAxisLabel, (XYZDataset) data,
                PlotOrientation.VERTICAL, true, false, false);

    case AUSTER_CICLOS:
        check(data, IntervalCategoryDataset.class, chartType);
        return ChartFactory.createAusterCiclosChart((IntervalCategoryDataset) data);

    default:
        throw new UnsupportedChartTypeException(chartType + " is not supported.");
    }
}

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

/**
 * Creates a sample chart./*w w  w .  ja va2 s.c om*/
 * 
 * @param dataset  the dataset for the chart.
 * 
 * @return A sample chart.
 */
protected JFreeChart createChart(CategoryDataset dataset) {

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

    GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
    KeyToGroupMap map = new KeyToGroupMap("G1");
    map.mapKeyToGroup("Product 1 (US)", "G1");
    map.mapKeyToGroup("Product 1 (Europe)", "G1");
    map.mapKeyToGroup("Product 1 (Asia)", "G1");
    map.mapKeyToGroup("Product 1 (Middle East)", "G1");
    map.mapKeyToGroup("Product 2 (US)", "G2");
    map.mapKeyToGroup("Product 2 (Europe)", "G2");
    map.mapKeyToGroup("Product 2 (Asia)", "G2");
    map.mapKeyToGroup("Product 2 (Middle East)", "G2");
    map.mapKeyToGroup("Product 3 (US)", "G3");
    map.mapKeyToGroup("Product 3 (Europe)", "G3");
    map.mapKeyToGroup("Product 3 (Asia)", "G3");
    map.mapKeyToGroup("Product 3 (Middle East)", "G3");
    renderer.setSeriesToGroupMap(map);

    renderer.setItemMargin(0.10);
    renderer.setDrawBarOutline(false);
    Paint p1 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0x22, 0xFF), 0.0f, 0.0f,
            new Color(0x88, 0x88, 0xFF));
    renderer.setSeriesPaint(0, p1);
    renderer.setSeriesPaint(4, p1);
    renderer.setSeriesPaint(8, p1);

    Paint p2 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0xFF, 0x22), 0.0f, 0.0f,
            new Color(0x88, 0xFF, 0x88));
    renderer.setSeriesPaint(1, p2);
    renderer.setSeriesPaint(5, p2);
    renderer.setSeriesPaint(9, p2);

    Paint p3 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0x22, 0x22), 0.0f, 0.0f,
            new Color(0xFF, 0x88, 0x88));
    renderer.setSeriesPaint(2, p3);
    renderer.setSeriesPaint(6, p3);
    renderer.setSeriesPaint(10, p3);

    Paint p4 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0xFF, 0x22), 0.0f, 0.0f,
            new Color(0xFF, 0xFF, 0x88));
    renderer.setSeriesPaint(3, p4);
    renderer.setSeriesPaint(7, p4);
    renderer.setSeriesPaint(11, p4);
    renderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));

    renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());

    SubCategoryAxis domainAxis = new SubCategoryAxis("Product / Month");
    domainAxis.setCategoryMargin(0.05);
    domainAxis.addSubCategory("Product 1");
    domainAxis.addSubCategory("Product 2");
    domainAxis.addSubCategory("Product 3");

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setDomainAxis(domainAxis);
    //plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
    plot.setRenderer(renderer);
    //   plot.setFixedLegendItems(createLegendItems());

    setCategorySummary(dataset);
    return chart;

}

From source file:org.metacsp.utility.UI.PlotBoxTLSmall.java

/**
 * Creates a chart for the PlotBoxBehavior
 * /* w w w. j  a  va  2 s. c om*/
 * @param dataset  A dataset for the chart.
 * 
 * @return A chart where the PlotBoxBehavior will be plotted.
 */
@SuppressWarnings("deprecation")
private JFreeChart createChart(CategoryDataset dataset) {

    //      String s = name;
    String s = null;
    String tit = null;
    String ax = null;
    //      if (first)
    //         tit = title + " (EST)";
    //      else if (last)
    //         ax = "Time";

    tit = this.name;

    chart = ChartFactory.createStackedBarChart(tit, // chart title
            s, // domain axis label
            ax, // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // the plot orientation
            false, // legend
            false, // tooltips
            false // urls
    );
    CategoryPlot plot = chart.getCategoryPlot();

    chart.getTitle().setHorizontalAlignment(HorizontalAlignment.LEFT);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

    //plot.getCategories();
    //CategoryItemRenderer renderer = plot.getRenderer();
    StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer();
    renderer.setItemLabelsVisible(true);
    renderer.setItemLabelGenerator(new LabelGenerator(true));
    ItemLabelPosition pos = new ItemLabelPosition(ItemLabelAnchor.INSIDE1, TextAnchor.TOP_RIGHT);
    renderer.setPositiveItemLabelPositionFallback(pos);
    for (int i = 0; i < dataset.getRowCount(); i++) {
        renderer.setSeriesPositiveItemLabelPosition(i, pos);
    }

    /*
    if (values.elementAt(0) instanceof ResourceLevel) {
       renderer.setItemLabelGenerator( new PlotBoxTL.LabelGenerator(true));
    }
    else
       renderer.setItemLabelGenerator( new PlotBoxTL.LabelGenerator(false));
    */
    renderer.setToolTipGenerator(new PlotBoxTooltip());
    plot.setRenderer(renderer);
    // renderer.getSeriesStroke(0).
    plot.setForegroundAlpha(0.8f);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLowerMargin(2.0);
    rangeAxis.setUpperMargin(2.0);

    //long origin = stl.getSerializableSimpleTimeline().getEarliestStartTime();
    //long horizon = stl.getSerializableSimpleTimeline().getLatestEndTime();
    long origin = stl.getPulses()[0].longValue();
    NumberFormat nf = new DecimalFormat();
    rangeAxis.setNumberFormatOverride(nf);
    if (this.range != null)
        rangeAxis.setRange(range);
    //rangeAxis.setRange((new Double(origin)).doubleValue(), (new Double(horizon)).doubleValue());

    ///// 0 should be replaced by the start of the horizon
    renderer.setBase(origin);

    //renderer.setBase();

    for (int i = 0; i < durations.length; i++) {
        if (stl.isInconsistent(values[i]))
            renderer.setSeriesPaint(i, new Color(198, 30, 69));
        else if (stl.isCritical(values[i]))
            renderer.setSeriesPaint(i, new Color(238, 234, 111));
        else if (stl.isUndetermined(values[i]))
            renderer.setSeriesPaint(i, new Color(255, 255, 255));
        else
            renderer.setSeriesPaint(i, new Color(111, 180, 238));
        renderer.setSeriesOutlinePaint(i, Color.black);
    }

    renderer.setBaseSeriesVisibleInLegend(false, false);

    renderer.setSeriesStroke(0, new BasicStroke(40f));

    return chart;
}

From source file:simz1.StackedBarChart.java

private JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createStackedBarChart("Sales of last week", "Day", "Sales fo the day",
            categorydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.white);
    StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer();
    stackedbarrenderer.setDrawBarOutline(false);
    stackedbarrenderer.setItemLabelsVisible(true);
    stackedbarrenderer.setSeriesItemLabelGenerator(0, new StandardCategoryItemLabelGenerator());
    return jfreechart;
}

From source file:com.artnaseef.jmeter.report.ResultCodesStackedReport.java

protected void createChart() {
    // create the chart...
    this.chart = ChartFactory.createStackedBarChart("Average Result Codes per Second", // chart title
            this.yAxisLabel, // x axis label
            "Samples", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );/*ww w .  j ava  2s  . c o  m*/

    //
    // Adjust colors for the chart.
    //
    CategoryPlot categoryPlot;
    categoryPlot = (CategoryPlot) this.chart.getPlot();
    categoryPlot.setBackgroundPaint(Color.WHITE);
    categoryPlot.setDomainGridlinePaint(Color.BLACK);
    categoryPlot.setRangeGridlinePaint(Color.BLACK);

    //
    // Customize the bar colors.
    //
    CategoryItemRenderer renderer = this.chart.getCategoryPlot().getRenderer();
    List rowKeys = this.dataset.getRowKeys();

    int cur = 0;
    Map<Integer, Integer> colorAdjustMap = new HashMap<>();
    while (cur < rowKeys.size()) {
        Integer resultCode = (Integer) rowKeys.get(cur);

        Color color;
        int group = resultCode / 100;
        switch (group) {
        case 2:
            color = Color.GREEN;
            break;

        case 3:
            color = Color.BLUE;
            break;

        case 4:
            color = Color.ORANGE;
            break;

        case 5:
            color = Color.RED;
            break;

        default:
            color = Color.GRAY;
            break;
        }

        color = this.adjustColor(colorAdjustMap, group, color);

        renderer.setSeriesPaint(cur, color);
        renderer.setSeriesOutlinePaint(cur, Color.BLACK);

        cur++;
    }
}

From source file:net.sf.jsfcomp.chartcreator.utils.ChartUtils.java

public static JFreeChart createChartWithCategoryDataSet(ChartData chartData) {
    JFreeChart chart = null;//from w  w  w .  j ava 2s.  c o m
    PlotOrientation plotOrientation = ChartUtils.getPlotOrientation(chartData.getOrientation());

    CategoryDataset dataset = (CategoryDataset) chartData.getDatasource();
    String type = chartData.getType();
    String xAxis = chartData.getXlabel();
    String yAxis = chartData.getYlabel();
    boolean is3d = chartData.isChart3d();
    boolean legend = chartData.isLegend();

    if (type.equalsIgnoreCase("bar")) {
        if (is3d == true) {
            chart = ChartFactory.createBarChart3D("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                    false);
        } else {
            chart = ChartFactory.createBarChart("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                    false);
        }
        setBarOutline(chart, chartData);
    } else if (type.equalsIgnoreCase("stackedbar")) {
        if (is3d == true) {
            chart = ChartFactory.createStackedBarChart3D("", xAxis, yAxis, dataset, plotOrientation, legend,
                    true, false);
        } else {
            chart = ChartFactory.createStackedBarChart("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                    false);
        }
        setBarOutline(chart, chartData);
    } else if (type.equalsIgnoreCase("line")) {
        if (is3d == true)
            chart = ChartFactory.createLineChart3D("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                    false);
        else
            chart = ChartFactory.createLineChart("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                    false);
    } else if (type.equalsIgnoreCase("area")) {
        chart = ChartFactory.createAreaChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false);
    } else if (type.equalsIgnoreCase("stackedarea")) {
        chart = ChartFactory.createStackedAreaChart("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                false);
    } else if (type.equalsIgnoreCase("waterfall")) {
        chart = ChartFactory.createWaterfallChart("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                false);
    } else if (type.equalsIgnoreCase("gantt")) {
        chart = ChartFactory.createGanttChart("", xAxis, yAxis, (IntervalCategoryDataset) dataset, legend, true,
                false);
    }

    CategoryPlot plot = (CategoryPlot) chart.getCategoryPlot();
    plot.setDomainGridlinesVisible(chartData.isDomainGridLines());
    plot.setRangeGridlinesVisible(chartData.isRangeGridLines());
    if (chartData.getGenerateMap() != null)
        plot.getRenderer().setBaseItemURLGenerator(new StandardCategoryURLGenerator(""));

    int seriesCount = plot.getDataset().getColumnCount();
    if (chartData.getLineStokeWidth() > 0) {
        for (int index = 0; index <= seriesCount; index++)
            plot.getRenderer().setSeriesStroke(index, new BasicStroke(chartData.getLineStokeWidth()));
    }

    setCategorySeriesColors(chart, chartData);

    setCategoryExtensions(chart, chartData);

    return chart;
}

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

private static JFreeChart createChart3(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createStackedBarChart("Public Opinion : Torture of Prisoners",
            "Country", "%", categorydataset, PlotOrientation.HORIZONTAL, false, true, false);
    jfreechart.getTitle().setMargin(2D, 0.0D, 0.0D, 0.0D);
    TextTitle texttitle = new TextTitle("Source: http://news.bbc.co.uk/1/hi/world/6063386.stm",
            new Font("Dialog", 0, 11));
    texttitle.setPosition(RectangleEdge.BOTTOM);
    texttitle.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    texttitle.setMargin(0.0D, 0.0D, 4D, 4D);
    jfreechart.addSubtitle(texttitle);// w  w  w .j av a 2  s. c o  m
    TextTitle texttitle1 = new TextTitle("(*) Across 27,000 respondents in 25 countries",
            new Font("Dialog", 0, 11));
    texttitle1.setPosition(RectangleEdge.BOTTOM);
    texttitle1.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    texttitle1.setMargin(4D, 0.0D, 2D, 4D);
    jfreechart.addSubtitle(texttitle1);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    LegendItemCollection legenditemcollection = new LegendItemCollection();
    legenditemcollection.add(new LegendItem("Against all torture", null, null, null,
            new java.awt.geom.Rectangle2D.Double(-6D, -3D, 12D, 6D), Color.green));
    legenditemcollection.add(new LegendItem("Some degree permissible", null, null, null,
            new java.awt.geom.Rectangle2D.Double(-6D, -3D, 12D, 6D), Color.red));
    categoryplot.setFixedLegendItems(legenditemcollection);
    categoryplot.setInsets(new RectangleInsets(5D, 5D, 5D, 20D));
    LegendTitle legendtitle = new LegendTitle(categoryplot);
    legendtitle.setPosition(RectangleEdge.BOTTOM);
    jfreechart.addSubtitle(legendtitle);
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setDomainGridlinePaint(Color.white);
    categoryplot.setDomainGridlinesVisible(true);
    categoryplot.setRangeGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setUpperMargin(0.0D);
    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setDrawBarOutline(false);
    GradientPaint gradientpaint = new GradientPaint(0.0F, 0.0F, Color.green, 0.0F, 0.0F, new Color(0, 64, 0));
    Color color = new Color(0, 0, 0, 0);
    GradientPaint gradientpaint1 = new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, new Color(64, 0, 0));
    barrenderer.setSeriesPaint(0, gradientpaint);
    barrenderer.setSeriesPaint(1, color);
    barrenderer.setSeriesPaint(2, gradientpaint1);
    return jfreechart;
}

From source file:jmemorize.gui.swing.panels.HistoryChartPanel.java

private JFreeChart createChart() {
    JFreeChart chart = ChartFactory.createStackedBarChart(null, // chart title
            null, // domain axis label
            Localization.get(LC.CHART_CARDS), // range axis label
            new DefaultCategoryDataset(), // data
            PlotOrientation.VERTICAL, // the plot orientation
            true, // include legend
            true, // tooltips
            false // urls
    );//from  w  ww .jav  a 2 s .co m

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    TickUnitSource tickUnits = NumberAxis.createIntegerTickUnits();
    plot.getRangeAxis().setStandardTickUnits(tickUnits); //CHECK use locale

    setupRenderer(plot);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    return chart;
}