Example E1211
Visible to All Users

How to create a Stacked Bar chart

The following example demonstrates how to create a Stacked Bar chart at runtime.

Resulting heatmap

Files to Look At

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

Series_StackedBarChart/Form1.cs(vb)
C#
using System; using System.Collections.Generic; using System.Windows.Forms; using DevExpress.XtraCharts; namespace Series_StackedBarChart { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // Create a chart and add it to the form: ChartControl chart = new ChartControl(); chart.Dock = DockStyle.Fill; this.Controls.Add(chart); // Bind the chart to a data source: chart.DataSource = DataPoint.GetDataPoints(); chart.SeriesTemplate.ChangeView(ViewType.StackedBar); chart.SeriesTemplate.SeriesDataMember = "Company"; chart.SeriesTemplate.SetDataMembers("Product", "Income"); // Enable series point labels, specify their text pattern and position: chart.SeriesTemplate.LabelsVisibility = DevExpress.Utils.DefaultBoolean.True; chart.SeriesTemplate.Label.TextPattern = "${V}M"; ((BarSeriesLabel)chart.SeriesTemplate.Label).Position = BarSeriesLabelPosition.Center; // Customize series view settings (for example, bar width): StackedBarSeriesView view = (StackedBarSeriesView)chart.SeriesTemplate.View; view.BarWidth = 0.8; // Disable minor tickmarks on the x-axis: XYDiagram diagram = (XYDiagram)chart.Diagram; diagram.AxisX.Tickmarks.MinorVisible = false; // Add a chart title: chart.Titles.Add(new ChartTitle { Text = "Sales by Products" }); // Specify legend settings: chart.Legend.MarkerMode = LegendMarkerMode.CheckBoxAndMarker; chart.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.Center; chart.Legend.AlignmentVertical = LegendAlignmentVertical.TopOutside; } public class DataPoint { public string Product { get; set; } public double Income { get; set; } public string Company { get; set; } public DataPoint(string product, double income, string company) { this.Product = product; this.Income = income; this.Company = company; } public static List<DataPoint> GetDataPoints() { List<DataPoint> data = new List<DataPoint> { new DataPoint("Camera", 34.96, "DevAV North"), new DataPoint("Camcorder", 56.26, "DevAV North"), new DataPoint("Flash", 45.982, "DevAV North"), new DataPoint("Smartphone", 67.14, "DevAV North"), new DataPoint("Smart Watch", 51.23, "DevAV North"), new DataPoint("Television", 57.443, "DevAV North"), new DataPoint("Home Audio", 45.83, "DevAV North"), new DataPoint("Headphone", 51.23, "DevAV North"), new DataPoint("Camera", 56.48, "DevAV South"), new DataPoint("Camcorder", 35.123, "DevAV South"), new DataPoint("Flash", 36.16, "DevAV South"), new DataPoint("Smartphone", 39.1, "DevAV South"), new DataPoint("Smart Watch", 34.6, "DevAV South"), new DataPoint("Television", 56.16, "DevAV South"), new DataPoint("Home Audio", 35.38, "DevAV South"), new DataPoint("Headphone", 58.1 , "DevAV South")}; return data; } } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.