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:org.squale.squaleweb.util.graph.RepartitionBarMaker.java

/**
 * @return le diagramme JFreeChart/*from   www.  j a  v a2  s .c o m*/
 */
public JFreeChart getChart() {
    JFreeChart retChart = super.getChart();
    if (null == retChart) {
        retChart = ChartFactory.createStackedBarChart(mTitle, mXLabel, mYLabel, mDataSet,
                PlotOrientation.HORIZONTAL, true, false, true);
        CategoryPlot plot = retChart.getCategoryPlot();
        ValueAxis xAxis = plot.getRangeAxis();
        final double LOWER_BOUND = 0;
        final double UPPER_BOUND = 100;
        xAxis.setRange(LOWER_BOUND, UPPER_BOUND);
        plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
        mRenderer = (StackedBarRenderer) plot.getRenderer();
        // Positionne les couleurs el les liens
        RepartitionBarUrlGenerator generator = new RepartitionBarUrlGenerator(mProjectId, mCurrentAuditId,
                mPreviousAuditId, mPracticeId, mFactorParentId, NB_SERIES_FOR_INT_GRAPH);
        mRenderer.setItemURLGenerator(generator);

        manageColor(NB_SERIES_FOR_INT_GRAPH);
        retChart.setBackgroundPaint(Color.WHITE);
    }
    return retChart;
}

From source file:org.fhaes.fhrecorder.util.ColorBar.java

/**
 * Creates a chart when given a data set.
 * //w w  w  . j  a  va  2 s.c om
 * @param dataset to be plotted.
 * @return the created chart.
 */
private static JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createStackedBarChart("", "", "", dataset, PlotOrientation.HORIZONTAL,
            false, true, false);

    chart.setPadding(RectangleInsets.ZERO_INSETS);
    chart.setBorderVisible(false);

    StackedBarRenderer renderer = new StackedBarRenderer();
    renderer.setBarPainter(new StandardBarPainter()); // Remove shine
    renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    renderer.setShadowVisible(false);

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setRenderer(renderer);
    // plot.setBackgroundAlpha(0.0f);

    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);

    plot.getRangeAxis().setVisible(false);
    plot.getRangeAxis().setLowerMargin(0);
    plot.getRangeAxis().setUpperMargin(0);

    plot.getDomainAxis().setVisible(false);
    plot.getDomainAxis().setLowerMargin(0);
    plot.getDomainAxis().setUpperMargin(0);

    return chart;
}

From source file:fi.smaa.jsmaa.gui.SMAA2GUIFactory.java

@Override
public ViewBuilder buildView(Object o) {
    if (o == treeModel.getCentralWeightsNode()) {
        JFreeChart chart = null;//from   ww  w  .j  a  va2s  .c o m
        if (isChartDrawable()) {
            chart = ChartFactory.createLineChart("", "Criterion", "Central Weight", centralWeightsDataset,
                    PlotOrientation.VERTICAL, true, true, false);
            LineAndShapeRenderer renderer = new LineAndShapeRenderer(true, true);
            chart.getCategoryPlot().setRenderer(renderer);
        }
        ResultsTable table = new ResultsTable(centralWeightsTM);
        table.setAutoCreateRowSorter(true);
        table.setDefaultRenderer(Object.class, new CentralWeightsCellRenderer(1.0));
        table.getTableHeader().setToolTipText("CF = Confidence Factor");
        return new ViewWithHeader("Central weight vectors",
                new ResultsView(parent, table, chart, FileNames.ICON_SCRIPT));
    } else if (o == treeModel.getRankAcceptabilitiesNode()) {
        JFreeChart chart = null;
        if (isChartDrawable()) {
            chart = ChartFactory.createStackedBarChart("", "Alternative", "Rank Acceptability",
                    rankAcceptabilitiesDataset, PlotOrientation.VERTICAL, true, true, false);
            chart.getCategoryPlot().getRangeAxis().setUpperBound(1.0);
        }
        ResultsTable table = new ResultsTable(rankAcceptabilitiesTM);
        table.setAutoCreateRowSorter(true);
        table.setDefaultRenderer(Object.class, new ResultsCellColorRenderer(1.0));
        table.getTableHeader()
                .setToolTipText("Ranks in descending order, 1 is the best, 2 the second best, etc.");
        return new ViewWithHeader("Rank acceptability indices",
                new ResultsView(parent, table, chart, FileNames.ICON_SCRIPT));
    } else {
        return super.buildView(o);
    }
}

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

/**
 * Generate a stacked bar graph representing build execution times across 
 * all builds in the list. //from   w  w  w  . j a va2  s  .co  m
 *
 * @param   builds  List of builds 
 * 
 * @return  Stacked graph representing build execution times across all builds 
 */
public static final JFreeChart getMetricChart(Vector<CMnDbBuildData> builds) {
    JFreeChart chart = null;

    // Get a list of all possible build metrics
    int[] metricTypes = CMnDbMetricData.getAllTypes();

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

        // Collect build metrics for each of the builds in the list 
        Collections.sort(builds, new CMnBuildIdComparator());
        Enumeration buildList = builds.elements();
        while (buildList.hasMoreElements()) {

            // Process the build metrics for the current build
            CMnDbBuildData build = (CMnDbBuildData) buildList.nextElement();
            Vector metrics = build.getMetrics();
            if ((metrics != null) && (metrics.size() > 0)) {
                // Sort the list of metrics to ensure they are displayed on the chart in a sensible order
                Collections.sort(metrics, new CMnMetricDateComparator());

                // Collect data for each of the build metrics in the current build 
                Enumeration metricList = metrics.elements();
                while (metricList.hasMoreElements()) {
                    CMnDbMetricData currentMetric = (CMnDbMetricData) metricList.nextElement();
                    // Get elapsed time in "minutes"
                    Long elapsedTime = new Long(currentMetric.getElapsedTime() / (1000 * 60));
                    Integer buildId = new Integer(build.getId());
                    String metricName = CMnDbMetricData.getMetricType(currentMetric.getType());
                    dataset.addValue(elapsedTime, metricName, buildId);

                } // while build has metrics

            } // if has metrics

        } // while list has elements

    } // if list has elements

    // API: ChartFactory.createStackedBarChart(title, domainAxisLabel, rangeAxisLabel, dataset, orientation, legend, tooltips, urls)
    chart = ChartFactory.createStackedBarChart("Build Metrics", "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.formatMetricChart(plot, dataset);

    return chart;
}

From source file:playground.dgrether.signalsystems.utils.DgSignalPlanChart.java

public JFreeChart createSignalPlanChart(String title, String xAxisTitle, String yAxisTitle) {
    JFreeChart chart = ChartFactory.createStackedBarChart(title, xAxisTitle, yAxisTitle, this.dataset,
            PlotOrientation.HORIZONTAL, false, false, false);
    DgDefaultAxisBuilder axis = new DgDefaultAxisBuilder();
    CategoryPlot plot = chart.getCategoryPlot();

    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.black);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    CategoryAxis xAxis = axis.createCategoryAxis(xAxisTitle);
    plot.setDomainAxis(xAxis);/*from ww  w  . ja  va2  s . co m*/
    ValueAxis yAxis = axis.createValueAxis(yAxisTitle);
    yAxis.setUpperBound(this.tMax);
    yAxis.setLowerBound(this.tMin);
    plot.setRangeAxis(yAxis);

    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.findRangeBounds(dataset);
    renderer.setShadowVisible(false);
    //      renderer.setItemMargin(10.005);
    renderer.setMaximumBarWidth(0.2);
    for (Entry<Integer, Color> ee : seriesColor.entrySet()) {
        renderer.setSeriesPaint(ee.getKey(), ee.getValue());
        //         renderer.setSeriesStroke(ee.getKey(), new BasicStroke(50));
    }
    plot.setRenderer(renderer);
    //      chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    //      chart.setBackgroundPaint(ChartColor.WHITE);
    //      chart.removeLegend();
    return chart;
}

From source file:com.voterData.graph.Graph.java

public static JFreeChart getGenderDistChart(Map<String, Double> dataMap) {
    DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
    for (String key : dataMap.keySet()) {
        if (key.equals("Male_Dem_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "DEM", "Male_2008");
        } else if (key.equals("Male_Rep_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "REP", "Male_2008");
        } else if (key.equals("Male_Una_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "UNA", "Male_2008");
        } else if (key.equals("Female_Dem_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "DEM", "Female_2008");
        } else if (key.equals("Female_Rep_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "REP", "Female_2008");
        } else if (key.equals("Female_Una_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "UNA", "Female_2008");
        } else if (key.equals("Male_Dem_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "DEM", "Male_2012");
        } else if (key.equals("Male_Rep_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "REP", "Male_2012");
        } else if (key.equals("Male_Una_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "UNA", "Male_2012");
        } else if (key.equals("Female_Dem_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "DEM", "Female_2012");
        } else if (key.equals("Female_Rep_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "REP", "Female_2012");
        } else if (key.equals("Female_Una_2012")) {
            defaultcategorydataset.addValue(dataMap.get(key), "UNA", "Female_2012");
        }//from w  w  w  .ja va 2s.  c  o m
    }
    JFreeChart jfreechart = ChartFactory.createStackedBarChart("Gender based Distribution", "Gender_Year",
            "% of Votes", defaultcategorydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer();
    stackedbarrenderer.setDrawBarOutline(false);
    stackedbarrenderer.setItemLabelsVisible(true);
    stackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    stackedbarrenderer.setSeriesItemLabelGenerator(0, new StandardCategoryItemLabelGenerator());
    stackedbarrenderer.setSeriesPaint(0, Color.blue);
    stackedbarrenderer.setSeriesPaint(1, Color.red);
    stackedbarrenderer.setSeriesPaint(2, Color.green);
    return jfreechart;

}

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

/**
 * Creates a sample chart./*from w  ww .ja va 2s.  c  o  m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return a sample chart.
 */
protected JFreeChart createChart(CategoryDataset dataset) {

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

    /*  CategoryPlot plot = (CategoryPlot) chart.getPlot();
      StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer();
      renderer.setItemLabelsVisible(true);*/

    CategoryPlot plot = chart.getCategoryPlot();
    CategoryItemRenderer renderer = new ExtendedStackedBarRenderer();
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    plot.setRenderer(renderer);

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

    StackedBarRenderer renderer2 = (StackedBarRenderer) plot.getRenderer();
    renderer2.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());

    setCategorySummary(dataset);
    return chart;
}

From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputHistogram.java

@Override
public void createChart(final IScope scope) {
    super.createChart(scope);
    jfreedataset.add(0, new DefaultCategoryDataset());
    PlotOrientation orientation = PlotOrientation.VERTICAL;
    if (reverse_axes) {
        orientation = PlotOrientation.HORIZONTAL;
    }//from www  . jav a 2  s  . c o  m
    if (style.equals(IKeyword.THREE_D)) {
        chart = ChartFactory.createBarChart3D(getName(), null, null, null, orientation, true, true, false);
    } else if (style.equals(IKeyword.STACK)) {
        chart = ChartFactory.createStackedBarChart(getName(), null, null, null, orientation, true, true, false);
    } else {
        chart = ChartFactory.createBarChart(getName(), null, null, null, orientation, true, true, false);

    }

}

From source file:org.psystems.dicom.browser.server.stat.StatDailyLoadChartServlet2.java

private JFreeChart getChart(CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createStackedBarChart("Stacked Bar Chart Demo 4", // chart title
            "Category", // domain axis label
            "", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // the plot orientation
            true, // legend
            true, // tooltips
            false // urls
    );//from  ww  w.j a v a 2s.c  om

    TextTitle title = new TextTitle("   ()", labelFont);
    title.setPaint(new Color(68, 99, 156));
    chart.setTitle(title);

    GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
    KeyToGroupMap map = new KeyToGroupMap("G1");
    map.mapKeyToGroup("product 1 (US)", "G1");
    map.mapKeyToGroup("product 1 (Europe)", "G1");

    renderer.setSeriesToGroupMap(map);

    BarPainter b = new StandardBarPainter();
    //        BarPainter b = new GradientBarPainter(0,0.9,0.9);

    renderer.setBarPainter(b);

    renderer.setSeriesPaint(0, color1);
    renderer.setSeriesPaint(1, color2);

    SubCategoryAxis domainAxis = new SubCategoryAxis("DCM  / JPG ");
    domainAxis.setCategoryMargin(0.05);
    domainAxis.setTickLabelFont(dateFont);
    //        domainAxis.addSubCategory("Product 1");
    //        domainAxis.addSubCategory("Product 2");
    //        domainAxis.addSubCategory("Product 3");

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setDomainAxis(domainAxis);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.red);
    plot.setRangeGridlinePaint(Color.lightGray);

    ValueAxis v = plot.getRangeAxis();
    v.setTickLabelFont(dateFont);
    //      plot.setRangeAxis(ValueAxis);

    //plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
    plot.setRenderer(renderer);
    plot.setFixedLegendItems(createLegendItems());
    return chart;

}

From source file:org.psystems.dicom.browser.server.stat.StatClientRequestsChartServlet2.java

private JFreeChart getChart(CategoryDataset dataset) {

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

    TextTitle title = new TextTitle("? ? ? (.)",
            labelFont);
    title.setPaint(new Color(68, 99, 156));
    chart.setTitle(title);

    GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
    KeyToGroupMap map = new KeyToGroupMap("G1");
    map.mapKeyToGroup("product 1 (US)", "G1");
    map.mapKeyToGroup("product 1 (Europe)", "G1");

    renderer.setSeriesToGroupMap(map);

    BarPainter b = new StandardBarPainter();
    //        BarPainter b = new GradientBarPainter(0,0.9,0.9);

    renderer.setBarPainter(b);

    renderer.setSeriesPaint(0, color1);
    renderer.setSeriesPaint(1, color2);

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

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setDomainAxis(domainAxis);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.red);
    plot.setRangeGridlinePaint(Color.lightGray);

    ValueAxis v = plot.getRangeAxis();
    v.setTickLabelFont(dateFont);
    //      plot.setRangeAxis(ValueAxis);

    //plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
    plot.setRenderer(renderer);
    plot.setFixedLegendItems(createLegendItems());
    return chart;

}