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.seagate.kinetic.monitor.view.DefaultKineticOverviewView.java

private JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createStackedBarChart("", "", "Total " + unitName, categorydataset,
            PlotOrientation.HORIZONTAL, true, true, false);
    keytogroupmap = new KeyToGroupMap("G1");
    keytogroupmap.mapKeyToGroup("Get", "G1");
    keytogroupmap.mapKeyToGroup("Put", "G1");
    keytogroupmap.mapKeyToGroup("Delete", "G1");
    groupedstackedbarrenderer.setSeriesToGroupMap(keytogroupmap);
    groupedstackedbarrenderer.setItemMargin(0.10000000000000001D);
    groupedstackedbarrenderer.setDrawBarOutline(false);

    GradientPaint gradientpaint = new GradientPaint(0.0F, 0.0F, new Color(34, 34, 255), 0.0F, 0.0F,
            new Color(136, 136, 255));
    groupedstackedbarrenderer.setSeriesPaint(0, gradientpaint);
    groupedstackedbarrenderer.setSeriesPaint(4, gradientpaint);
    groupedstackedbarrenderer.setSeriesPaint(8, gradientpaint);
    GradientPaint gradientpaint1 = new GradientPaint(0.0F, 0.0F, new Color(34, 255, 34), 0.0F, 0.0F,
            new Color(136, 255, 136));
    groupedstackedbarrenderer.setSeriesPaint(1, gradientpaint1);
    groupedstackedbarrenderer.setSeriesPaint(5, gradientpaint1);
    groupedstackedbarrenderer.setSeriesPaint(9, gradientpaint1);
    GradientPaint gradientpaint2 = new GradientPaint(0.0F, 0.0F, new Color(255, 34, 34), 0.0F, 0.0F,
            new Color(255, 136, 136));
    groupedstackedbarrenderer.setSeriesPaint(2, gradientpaint2);
    groupedstackedbarrenderer.setSeriesPaint(6, gradientpaint2);
    groupedstackedbarrenderer.setSeriesPaint(10, gradientpaint2);
    GradientPaint gradientpaint3 = new GradientPaint(0.0F, 0.0F, new Color(255, 255, 34), 0.0F, 0.0F,
            new Color(255, 255, 136));
    groupedstackedbarrenderer.setSeriesPaint(3, gradientpaint3);
    groupedstackedbarrenderer.setSeriesPaint(7, gradientpaint3);
    groupedstackedbarrenderer.setSeriesPaint(11, gradientpaint3);
    groupedstackedbarrenderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));

    return jfreechart;
}

From source file:com.jbombardier.console.charts.StackedBarChart.java

public JPanel createChart(String title) {
    JFreeChart jfreechart = ChartFactory.createStackedBarChart(title, "Category", "Value", categorydataset,
            PlotOrientation.VERTICAL, true, true, false);
    categoryplot = (CategoryPlot) jfreechart.getPlot();
    StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer();
    stackedbarrenderer.setDrawBarOutline(false);
    stackedbarrenderer.setBaseItemLabelsVisible(true);
    stackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());

    ChartPanel moo = new ChartPanel(jfreechart);
    moo.setMinimumDrawHeight(0);/*from w w w. j ava2  s  . co  m*/
    moo.setMinimumDrawWidth(0);
    moo.setMaximumDrawHeight(Integer.MAX_VALUE);
    moo.setMaximumDrawWidth(Integer.MAX_VALUE);
    return moo;
}

From source file:com.sonyericsson.jenkins.plugins.bfa.graphs.StackedBarChart.java

@Override
protected JFreeChart createGraph() {
    DefaultCategoryDataset dataset = createDataset();

    JFreeChart chart = ChartFactory.createStackedBarChart(getTitle(), getXAxisTitle(), getYAxisTitle(), dataset,
            PlotOrientation.VERTICAL, true, true, false);

    final CategoryPlot plot = chart.getCategoryPlot();
    int index = dataset.getRowIndex(NO_FAILURE);
    if (index >= 0) {
        plot.getRenderer().setSeriesVisibleInLegend(index, false);
    }//from  w  ww  .  j  av  a2s.  co m
    CategoryAxis domainAxis = plot.getDomainAxis();

    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setCategoryMargin(0);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    return chart;
}

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

/**
 * Creates a sample chart./*from   w  w w .j  a v a2s .c om*/
 * 
 * @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 1", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // the plot orientation
            true, // legend
            true, // tooltips
            false // urls
    );
    return chart;

}

From source file:org.squale.squaleweb.util.graph.AuditTimeMaker.java

/**
 * @return le diagramme JFreeChart/*from ww  w.j  a v a  2s. co m*/
 */
public JFreeChart getChart() {
    JFreeChart retChart = super.getChart();
    if (null == retChart) {
        // Appel  la factory pour crer le diagramme
        retChart = ChartFactory.createStackedBarChart(mTitle, mXLabel, mYLabel, mDataSet,
                PlotOrientation.VERTICAL, true, false, false);
        CategoryPlot plot = retChart.getCategoryPlot();
        ValueAxis xAxis = plot.getRangeAxis();
        plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
        // Le renderer pour avoir un diagramme en baton avec empilement
        mRenderer = (StackedBarRenderer) plot.getRenderer();
        // Appel de la mthode grant les couleurs du graphe
        // met le fond blanc
        retChart.setBackgroundPaint(Color.WHITE);
    }
    return retChart;
}

From source file:com.redhat.thermostat.byteman.plot.impl.TestPlotRenderer.java

void renderToFile(Collection<PlotRecord> records, String filename) throws Exception {
    DefaultCategoryDataset ds = new DefaultCategoryDataset();
    for (PlotRecord re : records) {
        Long label = re.getPeriodStart() + ((re.getPeriodEnd() - re.getPeriodStart()) / 2);
        ds.addValue(re.getValue(), re.getCategory(), label);
    }/*  w w w  .j  a  v a  2 s . c o m*/
    JFreeChart chart = ChartFactory.createStackedBarChart(EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, ds,
            PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(toColor("#FFFFFFFF"));
    plot.setBackgroundImageAlpha((float) 0.0d);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(toColor("#FFAAAAAA"));
    //        plot.getRangeAxis().setRange(new Range(ds.getMin(), ds.getMax() * 1.1));
    plot.getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    //        plot.getRangeAxis().setLabel(cf.rangeAxisLabel);
    //        colorAxis(plot.getRangeAxis());
    //        colorAxis(plot.getDomainAxis());
    //        plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI * 0.12d));
    //        plot.getDomainAxis().setLowerMargin(cf.domainAxisLowerMargin);
    //        plot.getDomainAxis().setUpperMargin(cf.domainAxisUpperMargin);
    //        plot.getDomainAxis().setLabel(cf.domainAxisLabel);
    BarRenderer3D barrenderer = new StackedBarRenderer3D(16.0d, 12.0d);
    barrenderer.setSeriesPaint(0, toColor("#00FFFFFF"));
    barrenderer.setSeriesPaint(1, toColor("#BB669900"));
    barrenderer.setSeriesPaint(2, toColor("#BBFF8800"));
    barrenderer.setWallPaint(toColor("#FFEEEEEE"));
    //        barrenderer.setBaseItemLabelsVisible(cf.baseItemLabelsVisible);
    barrenderer.setShadowVisible(false);
    barrenderer.setItemMargin(0.0d);
    plot.setRenderer(barrenderer);
    plot.setOutlineVisible(false);

    chartToSvg(chart, 1024, 600, filename);
}

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

/**
 * Creates a sample chart.//from  w w  w  . ja  v a  2 s  .  c  om
 * 
 * @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 3", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // the plot orientation
            true, // legend
            false, // tooltips
            false // urls
    );
    final CategoryPlot plot = chart.getCategoryPlot();
    //        final CategoryItemRenderer renderer = new ExtendedStackedBarRenderer();
    //      renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    //    plot.setRenderer(renderer);

    final ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setLowerMargin(0.15);
    rangeAxis.setUpperMargin(0.15);
    return chart;

}

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

/**
 * Creates a sample chart.//  ww w.  j av a 2 s  .  c om
 * 
 * @param dataset  the dataset.
 * 
 * @return a sample chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

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

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

    return chart;

}

From source file:com.swordlord.gozer.components.fop.graph.GFopStackedBarChart.java

public GFopStackedBarChart(IGozerFrameExtension gfe, GStackedBarChart chart) {
    super(gfe);//from  w w  w  . ja  v  a 2s .c  o  m

    DataBindingMember dbMemberRowKey = chart.getDataBindingMemberRowKey();
    DataBindingMember dbMemberColKey = chart.getDataBindingMemberColKey();
    DataBindingMember dbMemberValue = chart.getDataBindingMemberValue();
    DataBindingManager dbManager = chart.getDataBindingManager();

    DefaultCategoryDataset dcd = new DefaultCategoryDataset();

    List<DataRowBase> rowTests = dbManager.getRows(dbMemberValue);
    for (int j = 0; j < rowTests.size(); j++) {
        DataRowBase row = rowTests.get(j);

        String strKey = row.getPropertyAsStringForce(dbMemberRowKey.getRelativePathWithField());

        dcd.setValue(row.getPropertyAsInt(dbMemberValue.getRelativePathWithField()), strKey,
                row.getPropertyAsStringForce(dbMemberColKey.getRelativePathWithField()));
    }

    JFreeChart fc = ChartFactory.createStackedBarChart(chart.getTitle(), chart.getCategoryAxisLabel(),
            chart.getValueAxisLabel(), dcd, chart.getOrientation(), chart.getLegend(), false, false);

    // Do this in a more static way!
    StackedBarRenderer.setDefaultBarPainter(new StandardBarPainter());

    //chart.setBackgroundPaint(Color.white);
    if (chart.getSubTitle() != null) {
        fc.addSubtitle(new TextTitle(chart.getSubTitle()));
    }

    CategoryPlot plot = fc.getCategoryPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDrawingSupplier(chart.getDrawingSupplier());

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setVisible(chart.getCategoryAxisVisible());

    ValueAxis valueAxis = plot.getRangeAxis();
    valueAxis.setVisible(chart.getValueAxisVisible());

    /*
    //CategoryItemRenderer renderer = (CategoryItemRenderer) plot.getRenderer();
    for (int j = 0; j < rowKey.length; j++)
    {
       renderer.setSeriesItemLabelGenerator(j, new LabelGenerator(j, rowKey[j]));
       renderer.setSeriesItemLabelsVisible(j, true);
    }
    */
    StackedBarRenderer renderer = new StackedBarRenderer();

    for (int j = 0; j < dcd.getRowCount(); j++) {
        renderer.setSeriesItemLabelGenerator(j, new StandardCategoryItemLabelGenerator());
        renderer.setSeriesItemLabelsVisible(j, true);
    }

    //renderer.setLegendItemLabelGenerator(new LabelGenerator());
    renderer.setShadowVisible(false);

    plot.setRenderer(renderer);

    _image = new ChartImage("chart", fc, chart.getWidth(800), chart.getHeight(800));
}

From source file:com.manydesigns.portofino.chart.ChartStackedBarGenerator.java

protected JFreeChart createChart(ChartDefinition chartDefinition, CategoryDataset dataset,
        PlotOrientation plotOrientation) {
    return ChartFactory.createStackedBarChart(chartDefinition.getName(), chartDefinition.getXAxisName(),
            chartDefinition.getYAxisName(), dataset, plotOrientation, true, true, true);
}