Skip to main content

BarChartView Class

Contains settings that apply to bar and column series in a chart view.

Declaration

public class BarChartView extends BarChartViewBase

Remarks

When you add a BarSeries object to a chart, the chart creates a BarChartView object for the series. Call the Chart.getViews() method to access chart views.

To stack bars, call the BarChartView.setBarGrouping(value) method. Call the setOverlap(int value) method to specify the overlap of bars in a category.

Refer to the following help topic for additional information: Create Standard Charts — Presentation API for Java.

Example: Create a Stacked Column Chart with Series Lines

The following code snippet creates a stacked column chart, connects the columns with series lines, and displays values in the center of each column:

import java.io.*;
import java.nio.file.*;
import java.util.List;
import com.devexpress.docs.office.*;
import com.devexpress.docs.presentation.*;
import com.devexpress.system.drawing.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try (Presentation presentation = new Presentation()) {
            // Add a blank slide.
            presentation.getSlides().clear();
            Slide slide = new Slide(SlideLayoutType.BLANK);
            presentation.getSlides().add(slide);

            // Insert a chart that fills the slide.
            Chart chart = new Chart();
            chart.setWidth(presentation.getSlideSize().getWidth());
            chart.setHeight(presentation.getSlideSize().getHeight());
            slide.getShapes().add(chart);

            // Add two bar series.
            String[] names = { "Online", "Retail" };
            double[][] values = { { 12, 18, 15 }, { 14, 20, 19 } };
            for (int i = 0; i < names.length; i++) {
                BarSeries series = new BarSeries();
                series.setText(names[i]);
                series.setArguments(new ChartStringData(List.of("Q1", "Q2", "Q3")));
                series.setValues(new ChartNumericData(List.of(values[i][0], values[i][1], values[i][2])));
                chart.getSeries().add(series);
            }

            // Stack the columns and connect them with series lines.
            BarChartView view = (BarChartView) chart.getViews().get(0);
            view.setBarGrouping(BarChartGrouping.STACKED);
            view.setOverlap(100);
            view.setGapWidth(80);
            OutlineStyle seriesLine = new OutlineStyle();
            seriesLine.setFill(new SolidFill(Color.getGray()));
            seriesLine.setWidth(1.5f);
            ChartElement seriesLineProperties = new ChartElement();
            seriesLineProperties.setOutlineStyle(seriesLine);
            view.setSeriesLineProperties(seriesLineProperties);

            // Display values in the center of each column.
            view.getDataLabels().setShowValue(true);
            view.getDataLabels().setLabelPosition(BarDataLabelPosition.CENTER);

            // Save the presentation.
            Files.createDirectories(Path.of("output"));
            try (OutputStream output = Files.newOutputStream(Path.of("output", "Chart.pptx"))) {
                presentation.save(output);
            }
        }
    }
}

The following screenshot illustrates the result:

 Stacked column chart with series lines and centered data labels created with the DevExpress Presentation API for Java

Inherited Members

com.devexpress.system.JavaObject.clone()
com.devexpress.system.JavaObject.equals(java.lang.Object)
com.devexpress.system.JavaObject.hashCode()
com.devexpress.system.JavaObject.memberwiseClone()
com.devexpress.system.JavaObject.toString()
java.lang.Object.finalize()
java.lang.Object.getClass()
java.lang.Object.notify()
java.lang.Object.notifyAll()
java.lang.Object.wait()
java.lang.Object.wait(long)
java.lang.Object.wait(long,int)
See Also

BarChartView()

Initializes a new instance of the BarChartView class.

Declaration

public BarChartView()

Methods

getChartType() Method

Returns the chart type of the view.

Declaration

public ChartType getChartType()

Returns

Type Description
ChartType

The ChartType.BAR value.

getDataLabels() Method

Returns data label settings for all series in the view.

Declaration

public IBarDataLabels getDataLabels()

Returns

Type Description
IBarDataLabels

Data label settings.

Remarks

Call the BarSeries.getDataLabels() method to access data label settings for an individual series.

Refer to the following help topic for additional information: Customize Chart Data Labels — Presentation API for Java.

getOverlap() Method

Returns the overlap of bars in a category.

Declaration

public int getOverlap()

Returns

Type Description
int

The overlap as a percentage of the bar width (from -100 to 100).

getSeriesLineProperties() Method

Returns settings for series lines that connect bars in stacked bar charts.

Declaration

public ChartElement getSeriesLineProperties()

Returns

Type Description
ChartElement

Series line settings, or null if the view does not display series lines.

setOverlap(int value) Method

Sets the overlap of bars in a category.

Declaration

public void setOverlap(int value)

Parameters

Name Type Description
value int

The overlap as a percentage of the bar width (from -100 to 100).

Exceptions

Type Description
ArgumentOutOfRangeException

Thrown if the value parameter is less than -100 or greater than 100.

Remarks

The value range is from -100 to 100. Positive values overlap bars in a category. Negative values add space between bars.

If you do not call the setOverlap(value) method, the API uses 0.

setSeriesLineProperties(ChartElement value) Method

Sets settings for series lines that connect bars in stacked bar charts.

Declaration

public void setSeriesLineProperties(ChartElement value)

Parameters

Name Type Description
value ChartElement

Series line settings, or null to hide series lines.

Remarks

Series lines connect the ends of stacked bars in adjacent categories. To specify the line color and width, pass a ChartElement object with outline settings to the setSeriesLineProperties(value) method.

Note

Series lines take effect when you call the BarChartView.setBarGrouping(BarChartGrouping.STACKED) or setBarGrouping(BarChartGrouping.PERCENT_STACKED) method.