Example usage for org.jfree.chart.renderer.category StackedBarRenderer setBaseItemLabelsVisible

List of usage examples for org.jfree.chart.renderer.category StackedBarRenderer setBaseItemLabelsVisible

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.category StackedBarRenderer setBaseItemLabelsVisible.

Prototype

public void setBaseItemLabelsVisible(boolean visible) 

Source Link

Document

Sets the base flag that controls whether or not item labels are visible, and sends a RendererChangeEvent to all registered listeners.

Usage

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createStackedBarChart("Stacked Bar Chart Demo 7", "Category", "Value",
            categorydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer();
    stackedbarrenderer.setRenderAsPercentages(true);
    stackedbarrenderer.setDrawBarOutline(false);
    stackedbarrenderer.setBaseItemLabelsVisible(true);
    stackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    return jfreechart;
}

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

/**
 * DOC xqliu Comment method "createStackedBarChart".
 * /*w ww  .  j av  a 2s. c  om*/
 * @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: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);/* ww  w . j  a v  a  2  s.c  om*/
    moo.setMinimumDrawWidth(0);
    moo.setMaximumDrawHeight(Integer.MAX_VALUE);
    moo.setMaximumDrawWidth(Integer.MAX_VALUE);
    return moo;
}

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

/**
 * Creates a sample chart.//w  w w.  j a  v  a2  s . co  m
 * 
 * @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
    );
    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);

    StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setBaseItemLabelsVisible(true);
    renderer.setSeriesItemLabelGenerator(0, new StandardCategoryItemLabelGenerator());
    renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());

    setCategorySummary(dataset);
    return chart;

}

From source file:org.codehaus.mojo.dashboard.report.plugin.chart.StackedBarChartRenderer.java

/**
 * //w w  w. j av  a 2s . c  om
 */
public void createChart() {

    CategoryDataset categorydataset = (CategoryDataset) this.datasetStrategy.getDataset();
    report = ChartFactory.createStackedBarChart(this.datasetStrategy.getTitle(),
            this.datasetStrategy.getYAxisLabel(), this.datasetStrategy.getXAxisLabel(), categorydataset,
            PlotOrientation.HORIZONTAL, true, true, false);
    // report.setBackgroundPaint( Color.lightGray );
    report.setAntiAlias(false);
    report.setPadding(new RectangleInsets(5.0d, 5.0d, 5.0d, 5.0d));
    CategoryPlot categoryplot = (CategoryPlot) report.getPlot();
    categoryplot.setBackgroundPaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.lightGray);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    if (datasetStrategy instanceof CloverBarChartStrategy
            || datasetStrategy instanceof MultiCloverBarChartStrategy) {
        numberaxis.setRange(0.0D, StackedBarChartRenderer.NUMBER_AXIS_RANGE);
        numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    } else {
        numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }
    numberaxis.setLowerMargin(0.0D);
    StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer();
    stackedbarrenderer.setDrawBarOutline(false);
    stackedbarrenderer.setBaseItemLabelsVisible(true);
    stackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    stackedbarrenderer.setBaseItemLabelFont(StackedBarRenderer.DEFAULT_VALUE_LABEL_FONT.deriveFont(Font.BOLD));
    int height = (categorydataset.getColumnCount() * ChartUtils.STANDARD_BARCHART_ENTRY_HEIGHT * 2)
            + ChartUtils.STANDARD_BARCHART_ADDITIONAL_HEIGHT + 10;
    if (height > ChartUtils.MINIMUM_HEIGHT) {
        super.setHeight(height);
    } else {
        super.setHeight(ChartUtils.MINIMUM_HEIGHT);
    }
    Paint[] paints = this.datasetStrategy.getPaintColor();

    for (int i = 0; i < categorydataset.getRowCount() && i < paints.length; i++) {
        stackedbarrenderer.setSeriesPaint(i, paints[i]);
    }

}

From source file:com.itemanalysis.jmetrik.graph.barchart.BarChartPanel.java

public void setGraph() throws IllegalArgumentException {
    boolean hasGroupingVariable = false;
    if (command.getFreeOption("groupvar").hasValue()) {
        hasGroupingVariable = true;//from w ww .  j ava  2  s  .c o m
    }

    String name = command.getFreeOption("variable").getString();
    String xLabel = name;

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    String yLabel = "";
    if (command.getSelectOneOption("yaxis").isValueSelected("freq")) {
        yLabel = "Frequency";
    } else {
        yLabel = "Percentage";
    }

    if (command.getSelectOneOption("layout").isValueSelected("stacked")) {
        chart = ChartFactory.createStackedBarChart(command.getFreeOption("title").getString(), xLabel, yLabel,
                dataset, chartOrientation, hasGroupingVariable, //only show legend if has grouping variable
                true, false);
        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer();
        renderer.setDrawBarOutline(false);
        renderer.setBaseItemLabelsVisible(true);
        renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());

    } else if (command.getSelectOneOption("view").isValueSelected("3D")) {
        chart = ChartFactory.createBarChart3D(command.getFreeOption("title").getString(), xLabel, yLabel,
                dataset, chartOrientation, hasGroupingVariable, //only show legend if has grouping variable
                true, false);
    } else {
        chart = ChartFactory.createBarChart(command.getFreeOption("title").getString(), xLabel, yLabel, dataset,
                chartOrientation, hasGroupingVariable, //only show legend if has grouping variable
                true, false);

    }

    String sub = "";
    if (command.getFreeOption("subtitle").getString() != null) {
        sub = command.getFreeOption("subtitle").getString();
    }
    TextTitle subtitle1 = new TextTitle(sub);
    chart.addSubtitle(subtitle1);

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

    if (command.getSelectOneOption("layout").isValueSelected("layered")) {
        LayeredBarRenderer renderer = new LayeredBarRenderer();
        //            renderer.setDrawBarOutline(false);
        plot.setRenderer(renderer);
        plot.setRowRenderingOrder(SortOrder.DESCENDING);
    }

    chart.setPadding(new RectangleInsets(20.0, 5.0, 20.0, 5.0));

    ChartPanel panel = new ChartPanel(chart);
    panel.getPopupMenu().addSeparator();
    this.addJpgMenuItem(BarChartPanel.this, panel.getPopupMenu());

    panel.setPreferredSize(new Dimension(width, height));

    plot.setBackgroundPaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    //                plot.setForegroundAlpha(0.80f);
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(true);
    renderer.setShadowVisible(false);

    this.setBackground(Color.WHITE);
    this.add(panel);

}

From source file:edu.cuny.cat.ui.ProfitPlotPanel.java

public ProfitPlotPanel() {

    shoutSet = Collections.synchronizedSet(new HashSet<Shout>());

    registry = GameController.getInstance().getRegistry();

    setTitledBorder("Income and Expenses");

    dataset = new DefaultCategoryDataset();

    final JFreeChart chart = ChartFactory.createStackedBarChart("", "", "", dataset, PlotOrientation.HORIZONTAL,
            true, true, false);//from  www.  jav  a2  s.c  o  m
    // chart.setAntiAlias(false);
    chart.setBackgroundPaint(getBackground());
    final CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    final StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer();
    UIUtils.setDefaultBarRendererStyle(stackedbarrenderer);
    stackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    stackedbarrenderer.setBaseItemLabelsVisible(true);
    final ChartPanel chartPanel = new ChartPanel(chart);
    add(chartPanel, BorderLayout.CENTER);
}

From source file:edu.cuny.cat.ui.ScorePlotPanel.java

public ScorePlotPanel() {

    registry = GameController.getInstance().getRegistry();

    setTitledBorder("Scores");

    dataset = new DefaultCategoryDataset();

    chart = ChartFactory.createStackedBarChart("", "", "", dataset, PlotOrientation.HORIZONTAL, true, true,
            false);//from   w w w. jav  a 2s .  com
    // chart.setAntiAlias(false);
    chart.setBackgroundPaint(getBackground());
    final CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    final StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer();
    UIUtils.setDefaultBarRendererStyle(stackedbarrenderer);
    stackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    stackedbarrenderer.setBaseItemLabelsVisible(true);
    final ChartPanel chartPanel = new ChartPanel(chart);
    add(chartPanel, BorderLayout.CENTER);
}

From source file:com.signalcollect.sna.gephiconnectors.SignalCollectGephiConnector.java

/**
 * Gets the Label Propagation in the graph and creates a chart out of it
 * //from w w  w  .jav  a 2 s .  c om
 * @throws IOException
 */
public void getLabelPropagation() throws IOException {

    Map<Integer, Map<String, Integer>> m = LabelPropagation.run(graph, signalSteps.get());

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    final JFreeChart chart = ChartFactory.createStackedBarChart("Evolving Label Propagation", "Signal Step",
            null, dataset, PlotOrientation.VERTICAL, false, false, false);

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

    StackedBarRenderer renderer = new StackedBarRenderer();

    plot.setDataset(dataset);
    plot.setRenderer(renderer);
    renderer.setBaseItemLabelGenerator(
            new StandardCategoryItemLabelGenerator("{0} {2} {3}", NumberFormat.getInstance()));
    renderer.setBaseItemLabelsVisible(true);
    if (signalSteps.get() > 10) {
        long stepInterval = Math.round(new Double(signalSteps.get().doubleValue() / 10d));
        for (int i = (int) stepInterval; i <= signalSteps.get(); i += stepInterval) {
            Set<Map.Entry<String, Integer>> entrySet = m.get(new Integer(i)).entrySet();
            for (Map.Entry<String, Integer> subentry : entrySet) {
                dataset.addValue(subentry.getValue(), subentry.getKey(), new Integer(i));
            }
        }
    } else {
        for (Map.Entry<Integer, Map<String, Integer>> entry : m.entrySet()) {
            for (Map.Entry<String, Integer> subentry : entry.getValue().entrySet()) {
                dataset.addValue(subentry.getValue(), subentry.getKey(), entry.getKey());
            }
        }
    }
    renderer.setRenderAsPercentages(true);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setNumberFormatOverride(NumberFormat.getPercentInstance());

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(1200, 600));
    ApplicationFrame f = new ApplicationFrame("Label Propagation");
    f.setContentPane(chartPanel);
    f.pack();
    f.setVisible(true);
}

From source file:com.googlecode.logVisualizer.chart.HorizontalStackedBarChartBuilder.java

private JFreeChart createChart(final CategoryDataset dataset) {
    final JFreeChart chart = ChartFactory.createStackedBarChart(getTitle(), xLable, yLable, dataset,
            PlotOrientation.HORIZONTAL, isIncludeLegend(), true, false);
    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    final StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer();
    final CategoryAxis categoryAxis = plot.getDomainAxis();
    final NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();

    plot.setNoDataMessage("No data available");
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.black);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    setBarShadowVisible(chart, false);/*from  w  ww  .ja  va2s .co  m*/

    renderer.setDrawBarOutline(false);
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setBaseToolTipGenerator(
            new StandardCategoryToolTipGenerator("{1}, {2}", NumberFormat.getInstance()));

    categoryAxis.setCategoryMargin(0.02);
    categoryAxis.setUpperMargin(0.02);
    categoryAxis.setLowerMargin(0.02);
    numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberAxis.setUpperMargin(0.1);

    return chart;
}