Side-by-Side Full-Stacked Bar Chart

  • 3 minutes to read

Short Description

The Side-by-Side Full-Stacked Bar Chart is represented by the SideBySideFullStackedBarSeriesView object, which belongs to Bar Series Views. This view combines the advantages of both the Full-Stacked Bar and Side-by-Side Bar chart types, so that you can stack different bars, and combine them into groups shown side-by-side across the same axis value (via the SideBySideFullStackedBarSeriesView.StackedGroup property).

NOTE

When using series template binding for Side-by-Side Full-Stacked Bars, the SideBySideFullStackedBarSeriesView.StackedGroup property should be specified at runtime, in the ChartControl.BoundDataChanged event handler.

A Side-by-Side Full-Stacked Bar chart is shown in the image below. Note that this chart type is based upon the XYDiagram, so it can be rotated to show bars either vertically or horizontally.

SeriesView_SideBySideFullStackedBar

NOTE

A Side-by-Side Full-Stacked Bar chart can display series containing data points with positive or negative values. However, a series with positive values is stacked only with other series containing positive values; and a series with negative values is stacked with other series containing negative values.

Note that if a series contains data points with both positive and negative values, it is treated as a series with positive values, while all its negative values are treated as zeros.

Chart Type Characteristics

The table below lists the main characteristics of this chart type.

Feature Value
Series View type SideBySideFullStackedBarSeriesView
Diagram type 2D-XYDiagram
Number of arguments per series point 1
Number of values per series point 1
NOTE

For information on which chart types can be combined with the Side-by-Side Full-Stacked Bar Chart, refer to the Series Views Compatibility document.

Example

This example demonstrates how to populate the Chart Control with series that have the SideBySideFullStackedBarSeriesView at runtime:

private void Form1_Load(object sender, EventArgs e) {
    ConfigureChartData();
    ConfigureChartDiagram();

    chartControl.BoundDataChanged += this.OnChartBoundDataChanged;
}

private void ConfigureChartData() {
    chartControl.DataSource = repository.GetAll();
    chartControl.SeriesTemplate.SeriesDataMember = "SeriesId";
    chartControl.SeriesTemplate.SetDataMembers("Country", "Value");
    chartControl.SeriesTemplate.View = new SideBySideFullStackedBarSeriesView();
}

private void ConfigureChartDiagram() {
    if (!(chartControl.Diagram is XYDiagram diagram)) return;
    diagram.Rotated = true;
    diagram.AxisY.Label.TextPattern = "{VP:P}";
    diagram.AxisY.WholeRange.AutoSideMargins = false;
    diagram.AxisY.WholeRange.SideMarginsValue = 0;
}

private void OnChartBoundDataChanged(object sender, EventArgs e) {
    if (chartControl.Series.Count == 0) return;

    foreach (Series series in chartControl.Series) {
        SetViewStackGroupByDataItem(series);
    }
}
private void SetViewStackGroupByDataItem(Series series) {
    if (series.Points.Count == 0) return;
    PopulationItem item = series.Points[0].Tag as PopulationItem;
    if (item == null) return;

    SideBySideFullStackedBarSeriesView view = series.View as SideBySideFullStackedBarSeriesView;
    if (view == null) return;

    // This property specifies the Id of a bar group in which the Chart Control displays series.
    view.StackedGroup = item.Sex;
}
TIP

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E2093.