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:ispd.gui.auxiliar.Graficos.java

public ChartPanel criarGraficoNumTarefasAproveitamento(List<Tarefa> tarefas) {

    DefaultCategoryDataset dadosMflopProcessados = new DefaultCategoryDataset();
    int numExcesso = 0, numOK = 0, numCanceladas = 0;
    int i;/*from  ww  w  .  j  av a2  s.  c  o  m*/

    for (i = 0; i < tarefas.size(); i++) {

        if (tarefas.get(i).getEstado() != Tarefa.CANCELADO) {
            if (tarefas.get(i).getMflopsDesperdicados() != 0.0) {
                numExcesso++;
            } else {
                numOK++;
            }
        } else {
            numCanceladas++;
        }

    }

    dadosMflopProcessados.addValue(numExcesso, "Number of tasks", "Tasks with waste");
    dadosMflopProcessados.addValue(numOK, "Number of tasks", "Tasks without waste");
    dadosMflopProcessados.addValue(numCanceladas, "Number of tasks", "Canceled Tasks");

    JFreeChart jfc = ChartFactory.createStackedBarChart("Processing efficiency", //Titulo
            "", // Eixo X
            "Number of tasks", //Eixo Y
            dadosMflopProcessados, // Dados para o grafico
            PlotOrientation.VERTICAL, //Orientacao do grafico
            true, true, false); // exibir: legendas, tooltips, url
    ChartPanel graficoAproveitamentoNumero = new ChartPanel(jfc);
    graficoAproveitamentoNumero.setPreferredSize(new Dimension(600, 300));
    return graficoAproveitamentoNumero;

}

From source file:hudson.plugins.plot.PlotData.java

/**
 * Creates a Chart of the style indicated by getEffStyle() using the given dataset.
 * Defaults to using createLineChart.// w  w  w.ja v  a  2s . c  om
 */
private JFreeChart createChart(PlotCategoryDataset dataset) {
    String s = getUrlStyle();
    if (s.equalsIgnoreCase("area")) {
        return ChartFactory.createAreaChart(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
    }
    if (s.equalsIgnoreCase("bar")) {
        return ChartFactory.createBarChart(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
    }
    if (s.equalsIgnoreCase("bar3d")) {
        return ChartFactory.createBarChart3D(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
    }
    if (s.equalsIgnoreCase("line3d")) {
        return ChartFactory.createLineChart3D(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
    }
    if (s.equalsIgnoreCase("stackedarea")) {
        return ChartFactory.createStackedAreaChart(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(),
                dataset, PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
    }
    if (s.equalsIgnoreCase("stackedbar")) {
        return ChartFactory.createStackedBarChart(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(),
                dataset, PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
    }
    if (s.equalsIgnoreCase("stackedbar3d")) {
        return ChartFactory.createStackedBarChart3D(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(),
                dataset, PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
    }
    if (s.equalsIgnoreCase("waterfall")) {
        return ChartFactory.createWaterfallChart(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
    }
    return ChartFactory.createLineChart(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(), dataset,
            PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
}

From source file:ispd.gui.auxiliar.Graficos.java

public void criarGraficoPreempcao(RedeDeFilas rdf, List<Tarefa> tarefas) {

    DefaultCategoryDataset preempPorUsuario = new DefaultCategoryDataset();
    double mflopTotal = 0.0, tamanhoTotal;
    ArrayList<Integer> tarefasPreemp;
    tarefasPreemp = new ArrayList();
    int i, j, indexUsuario;

    for (i = 0; i < rdf.getUsuarios().size(); i++) {

        tarefasPreemp.add(0);/*  www . j  av  a 2s . com*/

    }

    for (i = 0; i < tarefas.size(); i++) {

        indexUsuario = rdf.getUsuarios().indexOf(tarefas.get(i).getProprietario());

        if (tarefas.get(i).getMflopsDesperdicados() > 0.0 && tarefas.get(i).getEstado() != Tarefa.CANCELADO) {
            tarefasPreemp.set(indexUsuario, 1 + tarefasPreemp.get(indexUsuario));
        }

        mflopTotal = 0.0;

    }

    for (i = 0; i < rdf.getUsuarios().size(); i++) {

        preempPorUsuario.addValue(tarefasPreemp.get(i), "Number of tasks", rdf.getUsuarios().get(i));

    }

    JFreeChart jfc = ChartFactory.createStackedBarChart("Tasks preempted per user", //Titulo
            "", // Eixo X
            "Number of tasks", //Eixo Y
            preempPorUsuario, // Dados para o grafico
            PlotOrientation.VERTICAL, //Orientacao do grafico
            true, true, false); // exibir: legendas, tooltips, url
    PreemptionPerUser = new ChartPanel(jfc);
    PreemptionPerUser.setPreferredSize(new Dimension(600, 300));
}

From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java

/**
 * DOC xqliu Comment method "createStackedBarChart".
 * /*from   w w w. j  a v a  2 s  .c o m*/
 * @param title
 * @param domainAxisLabel
 * @param rangeAxisLabel
 * @param dataset
 * @param orientation
 * @param legend
 * @param tooltips
 * @param urls
 * @return
 */
public static JFreeChart createStackedBarChart(String title, String domainAxisLabel, String rangeAxisLabel,
        CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) {
    // ADD msjian TDQ-5112 2012-4-10: after upgrate to jfreechart-1.0.12.jar, change the default chart wallPaint
    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    // TDQ-5112~
    final JFreeChart chart = ChartFactory.createStackedBarChart(title, domainAxisLabel, rangeAxisLabel, dataset,
            orientation, legend, tooltips, urls);

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

    StackedBarRenderer sbr = (StackedBarRenderer) plot.getRenderer();
    sbr.setBaseItemLabelsVisible(true);
    sbr.setRenderAsPercentages(true);
    sbr.setBaseItemLabelGenerator(new DQRuleItemLabelGenerator("{3}", NumberFormat.getIntegerInstance())); //$NON-NLS-1$
    sbr.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    // ADD xqliu 2010-03-10 feature 10834
    // sbr.setBaseToolTipGenerator(new DQRuleToolTipGenerator(ChartDecorator.NEW_TOOL_TIP_FORMAT_STRING,
    // NumberFormat
    // .getInstance()));
    // ~10834

    // ADD TDQ-5251 msjian 2012-7-31: do not display the shadow
    sbr.setShadowVisible(false);
    // TDQ-5251~

    NumberAxis axis = (NumberAxis) plot.getRangeAxis();
    axis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    axis.setUpperMargin(0.05f);
    axis.setLowerMargin(0.01f);

    return chart;
}

From source file:ispd.gui.auxiliar.Graficos.java

public ChartPanel gerarGraficoPorMaquina(List<Tarefa> tarefas, String maq) {
    DefaultCategoryDataset dadosMflopProcessados = new DefaultCategoryDataset();
    int i, j, histIndex = -1;
    CS_Maquina alvo = null;/*from  w  w w  . j a  v a2 s .  co m*/
    Tarefa task = null;
    double mflopUsado = 0.0;
    double mflopPerdido = 0.0;
    Double tempo;

    for (i = 0; i < rede.getMaquinas().size(); i++) {
        if (rede.getMaquinas().get(i).getId().equals(maq)) {
            alvo = rede.getMaquinas().get(i);
            break;
        }
    }

    if (alvo != null) {

        for (i = 0; i < alvo.getHistorico().size(); i++) {

            if (alvo.getHistorico().get(i).getMflopsDesperdicados() > 0.0) {

                for (j = 0; j < alvo.getHistorico().get(i).getHistoricoProcessamento().size(); j++) {

                    if (alvo.getHistorico().get(i).getHistoricoProcessamento().get(j).getId()
                            .equals(alvo.getId())) {

                        tempo = alvo.getHistorico().get(i).getTempoFinal().get(j)
                                - alvo.getHistorico().get(i).getTempoInicial().get(j);
                        if (alvo.getHistorico().get(i).getCheckPoint() != 0.0) {
                            mflopUsado += alvo.getMflopsProcessados(tempo)
                                    / alvo.getHistorico().get(i).getCheckPoint()
                                    - alvo.getMflopsProcessados(tempo)
                                            % alvo.getHistorico().get(i).getCheckPoint();
                            mflopPerdido += alvo.getMflopsProcessados(tempo)
                                    % alvo.getHistorico().get(i).getCheckPoint();
                        } else {
                            mflopPerdido += alvo.getMflopsProcessados(tempo);
                        }

                    }

                }

            } else {

                for (j = 0; j < alvo.getHistorico().get(i).getHistoricoProcessamento().size(); j++) {

                    if (alvo.getHistorico().get(i).getHistoricoProcessamento().get(j).getId()
                            .equals(alvo.getId())) {

                        tempo = alvo.getHistorico().get(i).getTempoFinal().get(j)
                                - alvo.getHistorico().get(i).getTempoInicial().get(j);
                        mflopUsado += alvo.getMflopsProcessados(tempo);

                    }

                }

            }

        }

        dadosMflopProcessados.addValue((mflopUsado / (mflopPerdido + mflopUsado)) * 100.0, "Usefull Processing",
                "MFlop Usage");
        dadosMflopProcessados.addValue((mflopPerdido / (mflopPerdido + mflopUsado)) * 100.0,
                "Wasted Processing", "MFlop Usage");

        JFreeChart jfc = ChartFactory.createStackedBarChart(
                "Processing efficiency for resource " + alvo.getId(), //Titulo
                "", // Eixo X
                "% of total Units executed", //Eixo Y
                dadosMflopProcessados, // Dados para o grafico
                PlotOrientation.VERTICAL, //Orientacao do grafico
                true, true, false); // exibir: legendas, tooltips, url
        ChartPanel graficoAproveitamentoMaquina = new ChartPanel(jfc);
        graficoAproveitamentoMaquina.setPreferredSize(new Dimension(600, 300));
        return graficoAproveitamentoMaquina;
    }

    return null;
}

From source file:com.modeln.build.ctrl.charts.CMnBuildListChart.java

/**
 * Generate a stacked bar graph representing test execution time for each 
 * product area. /*www  .j a va 2  s .  c o m*/
 *
 * @param   builds   List of builds
 * @param   suites   List of test suites
 * @param   areas    List of product areas 
 * 
 * @return  Stacked bar chart representing test execution times across all builds 
 */
public static final JFreeChart getAreaTestTimeChart(Vector<CMnDbBuildData> builds,
        Vector<CMnDbTestSuite> suites, Vector<CMnDbFeatureOwnerData> areas) {
    JFreeChart chart = null;

    // Collect the total times for each build, organized by area
    // This hashtable maps a build to the area/time information for that build
    Hashtable<Integer, Hashtable> buildTotals = new Hashtable<Integer, Hashtable>();

    // Generate placeholders for each build so the chart maintains a 
    // format consistent with the other charts that display build information
    HashSet areaNames = new HashSet();
    if (builds != null) {
        Enumeration buildList = builds.elements();
        while (buildList.hasMoreElements()) {
            CMnDbBuildData build = (CMnDbBuildData) buildList.nextElement();
            // Create the empty area list
            buildTotals.put(new Integer(build.getId()), new Hashtable<String, Long>());
        }
    }

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    if ((suites != null) && (suites.size() > 0)) {

        // Collect build test numbers for each of the builds in the list 
        Enumeration suiteList = suites.elements();
        while (suiteList.hasMoreElements()) {

            // Process the test summary for the current build
            CMnDbTestSuite suite = (CMnDbTestSuite) suiteList.nextElement();
            Integer buildId = new Integer(suite.getParentId());
            Long elapsedTime = new Long(suite.getElapsedTime());

            // Parse the build information so we can track the time by build
            Hashtable<String, Long> areaTime = null;
            if (buildTotals.containsKey(buildId)) {
                areaTime = (Hashtable) buildTotals.get(buildId);
            } else {
                areaTime = new Hashtable<String, Long>();
                buildTotals.put(buildId, areaTime);
            }

            // Iterate through each product area to determine who owns this suite
            CMnDbFeatureOwnerData area = null;
            Iterator iter = areas.iterator();
            while (iter.hasNext()) {
                CMnDbFeatureOwnerData currentArea = (CMnDbFeatureOwnerData) iter.next();
                if (currentArea.hasFeature(suite.getGroupName())) {
                    area = currentArea;
                }
            }

            // Add the elapsed time for the current suite to the area total
            Long totalValue = null;
            String areaName = area.getDisplayName();
            areaNames.add(areaName);
            if (areaTime.containsKey(areaName)) {
                Long oldTotal = (Long) areaTime.get(areaName);
                totalValue = oldTotal + elapsedTime;
            } else {
                totalValue = elapsedTime;
            }
            areaTime.put(areaName, totalValue);

        } // while list has elements

        // Populate the data set with the area times for each build
        Collections.sort(builds, new CMnBuildIdComparator());
        Iterator buildIter = builds.iterator();
        while (buildIter.hasNext()) {
            CMnDbBuildData build = (CMnDbBuildData) buildIter.next();
            Integer buildId = new Integer(build.getId());
            Hashtable areaTime = (Hashtable) buildTotals.get(buildId);

            Iterator areaKeys = areaNames.iterator();
            while (areaKeys.hasNext()) {
                String area = (String) areaKeys.next();
                Long time = (Long) areaTime.get(area);
                if (time != null) {
                    // Convert the time from milliseconds to minutes
                    time = time / (1000 * 60);
                } else {
                    time = new Long(0);
                }
                dataset.addValue(time, area, buildId);
            }
        }

    } // if list has elements

    // API: ChartFactory.createStackedBarChart(title, domainAxisLabel, rangeAxisLabel, dataset, orientation, legend, tooltips, urls)
    chart = ChartFactory.createStackedBarChart("Automated Tests by Area", "Builds", "Execution Time (min)",
            dataset, PlotOrientation.VERTICAL, true, true, false);

    // get a reference to the plot for further customization...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    chartFormatter.formatAreaChart(plot, dataset);

    return chart;
}

From source file:msi.gama.outputs.layers.ChartLayerStatement.java

private void createChart(final IScope scope) {
    switch (type) {
    case SERIES_CHART: {
        chart = ChartFactory.createXYLineChart(getName(), "time", "", null, PlotOrientation.VERTICAL, true,
                false, false);//from  ww  w .j ava 2  s  .c om
        break;
    }
    case PIE_CHART: {
        if (style.equals(IKeyword.THREE_D)) {
            chart = ChartFactory.createPieChart3D(getName(), null, false, true, false);
        } else if (style.equals(IKeyword.RING)) {
            chart = ChartFactory.createRingChart(getName(), null, false, true, false);
        } else if (style.equals(IKeyword.EXPLODED)) {
            chart = ChartFactory.createPieChart(getName(), null, false, true, false);
            exploded = true;
        } else {
            chart = ChartFactory.createPieChart(getName(), null, false, true, false);
        }
        break;
    }
    case HISTOGRAM_CHART: {
        if (style.equals(IKeyword.THREE_D)) {
            chart = ChartFactory.createBarChart3D(getName(), null, null, null, PlotOrientation.VERTICAL, true,
                    true, false);
        } else if (style.equals(IKeyword.STACK)) {
            chart = ChartFactory.createStackedBarChart(getName(), null, null, null, PlotOrientation.VERTICAL,
                    true, true, false);
        } else {
            chart = ChartFactory.createBarChart(getName(), null, null, null, PlotOrientation.VERTICAL, true,
                    true, false);
        }
        break;
    }
    case XY_CHART:
        chart = ChartFactory.createXYLineChart(getName(), "", "", null, PlotOrientation.VERTICAL, true, false,
                false);
        break;
    case SCATTER_CHART:
        chart = ChartFactory.createXYLineChart(getName(), "", "", null, PlotOrientation.VERTICAL, true, false,
                false);
        break;
    case BOX_WHISKER_CHART: {
        chart = ChartFactory.createBoxAndWhiskerChart(getName(), "Time", "Value",
                (BoxAndWhiskerCategoryDataset) dataset, true);
        chart.setBackgroundPaint(new Color(249, 231, 236));

        break;
    }
    }
    Plot plot = chart.getPlot();
    chart.getTitle().setFont(getTitleFont());
    if (backgroundColor == null) {
        plot.setBackgroundPaint(null);
        chart.setBackgroundPaint(null);
        chart.setBorderPaint(null);
        if (chart.getLegend() != null) {
            chart.getLegend().setBackgroundPaint(null);
        }
    } else {
        Color bg = backgroundColor;
        chart.setBackgroundPaint(bg);
        plot.setBackgroundPaint(bg);
        chart.setBorderPaint(bg);
        if (chart.getLegend() != null) {
            chart.getLegend().setBackgroundPaint(bg);
        }
    }
    // chart.getLegend().setItemPaint(axesColor);
    // chart.getLegend().setBackgroundPaint(null);

    if (plot instanceof CategoryPlot) {
        final CategoryPlot pp = (CategoryPlot) chart.getPlot();
        pp.setDomainGridlinePaint(axesColor);
        pp.setRangeGridlinePaint(axesColor);
        // plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
        // plot.setDomainCrosshairVisible(true);
        pp.setRangeCrosshairVisible(true);
    } else if (plot instanceof XYPlot) {
        final XYPlot pp = (XYPlot) chart.getPlot();
        pp.setDomainGridlinePaint(axesColor);
        pp.setRangeGridlinePaint(axesColor);
        pp.setDomainCrosshairPaint(axesColor);
        pp.setRangeCrosshairPaint(axesColor);
        pp.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
        pp.setDomainCrosshairVisible(true);
        pp.setRangeCrosshairVisible(true);
    }
}

From source file:hudson.plugins.plot.Plot.java

/**
 * Creates a Chart of the style indicated by getEffStyle() using the given
 * dataset. Defaults to using createLineChart.
 *//*from  w ww .j av a2 s  .c  o  m*/
private JFreeChart createChart(PlotCategoryDataset dataset) {
    String s = getUrlStyle();
    if ("area".equalsIgnoreCase(s)) {
        return ChartFactory.createAreaChart(getURLTitle(), /*
                                                            * categoryAxisLabel=
                                                            */null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*
                                                        * tooltips
                                                        * =
                                                        */
                true, /* url= */false);
    }
    if ("bar".equalsIgnoreCase(s)) {
        return ChartFactory.createBarChart(getURLTitle(), /*
                                                           * categoryAxisLabel=
                                                           */null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*
                                                        * tooltips
                                                        * =
                                                        */
                true, /* url= */false);
    }
    if ("bar3d".equalsIgnoreCase(s)) {
        return ChartFactory.createBarChart3D(getURLTitle(), /*
                                                             * categoryAxisLabel
                                                             * =
                                                             */null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*
                                                        * tooltips
                                                        * =
                                                        */
                true, /* url= */false);
    }
    if ("line3d".equalsIgnoreCase(s)) {
        return ChartFactory.createLineChart3D(getURLTitle(), /*
                                                              * categoryAxisLabel
                                                              * =
                                                              */null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*
                                                        * tooltips
                                                        * =
                                                        */
                true, /* url= */false);
    }
    if ("lineSimple".equalsIgnoreCase(s)) {
        return ChartFactory.createLineChart(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
    }

    if ("stackedarea".equalsIgnoreCase(s)) {
        return ChartFactory.createStackedAreaChart(getURLTitle(), /*
                                                                   * categoryAxisLabel
                                                                   * =
                                                                   */null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*
                                                        * tooltips
                                                        * =
                                                        */
                true, /* url= */false);
    }
    if ("stackedbar".equalsIgnoreCase(s)) {
        return ChartFactory.createStackedBarChart(getURLTitle(), /*
                                                                  * categoryAxisLabel
                                                                  * =
                                                                  */null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*
                                                        * tooltips
                                                        * =
                                                        */
                true, /* url= */false);
    }
    if ("stackedbar3d".equalsIgnoreCase(s)) {
        return ChartFactory.createStackedBarChart3D(getURLTitle(), /*
                                                                    * categoryAxisLabel
                                                                    * =
                                                                    */null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*
                                                        * tooltips
                                                        * =
                                                        */
                true, /* url= */false);
    }
    if ("waterfall".equalsIgnoreCase(s)) {
        return ChartFactory.createWaterfallChart(getURLTitle(), /*
                                                                 * categoryAxisLabel
                                                                 * =
                                                                 */null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*
                                                        * tooltips
                                                        * =
                                                        */
                true, /* url= */false);
    }
    return ChartFactory.createLineChart(getURLTitle(), /* categoryAxisLabel= */
            null, getYaxis(), dataset, PlotOrientation.VERTICAL, hasLegend(), /* tooltips= */true,
            /* url= */false);
}

From source file:org.oscarehr.web.reports.ocan.NeedRatingOverTimeReportGenerator.java

private JFreeChart generateNeedsOverTimeChart() {

    CategoryDataset dataset = this.createDataset();

    JFreeChart chart = ChartFactory.createStackedBarChart("Needs over Time (Consumer and Staff)", // chart title
            "Assessments", // x axis label
            "# of Domain", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );//from  ww w  .  jav  a 2s .co  m

    chart.setBackgroundPaint(Color.LIGHT_GRAY);

    GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
    KeyToGroupMap map = new KeyToGroupMap("G1");
    map.mapKeyToGroup("Consumer (Unknown)", "G1");
    map.mapKeyToGroup("Consumer (No Needs)", "G1");
    map.mapKeyToGroup("Consumer (Met Needs)", "G1");
    map.mapKeyToGroup("Consumer (Unmet Needs)", "G1");

    map.mapKeyToGroup("Staff (Unknown)", "G2");
    map.mapKeyToGroup("Staff (No Needs)", "G2");
    map.mapKeyToGroup("Staff (Met Needs)", "G2");
    map.mapKeyToGroup("Staff (Unmet Needs)", "G2");

    renderer.setSeriesToGroupMap(map);
    renderer.setItemMargin(0.1);
    //renderer.setItemLabelsVisible(true);
    renderer.setMaximumBarWidth(15);

    Paint p1 = Color.GREEN;
    renderer.setSeriesPaint(0, p1);
    renderer.setSeriesPaint(4, p1);
    renderer.setSeriesPaint(7, p1);

    Paint p2 = Color.BLUE;
    renderer.setSeriesPaint(1, p2);
    renderer.setSeriesPaint(5, p2);
    renderer.setSeriesPaint(8, p2);

    Paint p3 = new Color(255, 255, 153);
    renderer.setSeriesPaint(2, p3);
    renderer.setSeriesPaint(6, p3);
    renderer.setSeriesPaint(9, p3);

    Paint p4 = Color.ORANGE;
    renderer.setSeriesPaint(3, p4);
    renderer.setSeriesPaint(7, p4);
    renderer.setSeriesPaint(10, p4);

    SubCategoryAxis domainAxis = new SubCategoryAxis("Assessments");
    domainAxis.setCategoryMargin(0.05);
    domainAxis.addSubCategory("Consumer");
    domainAxis.addSubCategory("Staff");
    domainAxis.setMinorTickMarkInsideLength(10);
    domainAxis.setMinorTickMarkInsideLength(10);
    domainAxis.setMinorTickMarksVisible(true);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setDomainAxis(domainAxis);
    plot.setRenderer(renderer);

    LegendItemCollection result = new LegendItemCollection();
    LegendItem item1 = new LegendItem("Unknown", Color.GREEN);
    LegendItem item2 = new LegendItem("No Needs", Color.BLUE);
    LegendItem item3 = new LegendItem("Met Needs", new Color(255, 255, 153));
    LegendItem item4 = new LegendItem("Unmet Needs", Color.ORANGE);

    result.add(item1);
    result.add(item2);
    result.add(item3);
    result.add(item4);

    plot.setFixedLegendItems(result);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.black);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setRange(new Range(0, 24), true, false);
    rangeAxis.setTickUnit(new NumberTickUnit(4));

    plot.getDomainAxis().setCategoryMargin(0.35);

    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.BASELINE_LEFT));

    return chart;
}

From source file:org.pentaho.chart.plugin.jfreechart.JFreeChartFactoryEngine.java

public JFreeChart makeBarChart(ChartModel chartModel, MultiSeriesDataModel dataModel,
        IChartLinkGenerator linkGenerator) {
    DefaultCategoryDataset categoryDataset = createCategoryDataset(dataModel);
    org.pentaho.chart.model.TwoAxisPlot twoAxisPlot = (org.pentaho.chart.model.TwoAxisPlot) chartModel
            .getPlot();/* ww  w.j  a  v a  2  s.com*/

    String title = "";
    if ((chartModel.getTitle() != null) && (chartModel.getTitle().getText() != null)
            && (chartModel.getTitle().getText().trim().length() > 0)) {
        title = chartModel.getTitle().getText();
    }
    AxesLabels axesLabels = getAxesLabels(chartModel);
    PlotOrientation plotOrientation = (twoAxisPlot.getOrientation() == Orientation.HORIZONTAL)
            ? PlotOrientation.HORIZONTAL
            : PlotOrientation.VERTICAL;
    boolean showLegend = (chartModel.getLegend() != null) && (chartModel.getLegend().getVisible());
    JFreeChart chart = null;

    if (BarPlotFlavor.THREED == ((BarPlot) twoAxisPlot).getFlavor()) {
        chart = ChartFactory.createBarChart3D(title, axesLabels.domainAxisLabel, axesLabels.rangeAxisLabel,
                categoryDataset, plotOrientation, showLegend, true, false);
    } else if (BarPlotFlavor.STACKED == ((BarPlot) twoAxisPlot).getFlavor()) {
        chart = ChartFactory.createStackedBarChart(title, axesLabels.domainAxisLabel, axesLabels.rangeAxisLabel,
                categoryDataset, plotOrientation, showLegend, true, false);
    } else {
        chart = ChartFactory.createBarChart(title, axesLabels.domainAxisLabel, axesLabels.rangeAxisLabel,
                categoryDataset, plotOrientation, showLegend, true, false);
    }

    initCategoryPlot(chart, chartModel, linkGenerator);
    initChart(chart, chartModel);

    return chart;
}