Create Stacked Bar Programmatically

Thread is closed for posting
2 posts, 0 answers
  1. Michelle
    Michelle avatar
    7 posts
    Member since:
    May 2012

    Posted 08 Aug 2012 Link to this post

    protected void CreateStackedbBar()
        RadChart rcOTDBar = new RadChart();
        List<ChartData> objList = _objBLL.GetData();
        rcOTDBar.DataSource = objList;
        rcOTDBar.DataGroupColumn = "Group"; // "Grade A", "Grade B", "Grade C"
        rcOTDBar.PlotArea.XAxis.DataLabelsColumn = "ColumnName"; //"Jan", "Feb", "Mar", "Apr"
        rcOTDBar.Series[0].Type = ChartSeriesType.StackedBar;
        rcOTDBar.Series[1].Type = ChartSeriesType.StackedBar;
        rcOTDBar.Series[2].Type = ChartSeriesType.StackedBar;
        rcOTDBar.Series[3].Type = ChartSeriesType.StackedBar;


    I was trying to create stacked bar programmatically using the code above. The desired result is as attached. However it doesnt seems to show the values using the code attached. Please help.

  2. Evgenia
    Evgenia avatar
    1437 posts

    Posted 09 Aug 2012 Link to this post

    Hello Michelle,

     There is no need to use Grouping to achieve your scenario. The grouping feature should be used when you have repeating values in a column of your datasource. It creates as many series as the number of distinct values in this column. For more information, you can review our documentation.
    To have stacked bars as shown on your sample image you may follow our help topic and demo. The topic demmonstrates how you can bind a single series to a List of objects. However to have stacked bars with three bars in a stack , you will need three series. The approach is absolutely the same, but you should extend the Product class in the topic with two more int properties (for the two more bar series). Of course, you'll need to populate the collection of instances of the Product class with your new data.
    Finally just set the Type of the series to StackedBar and Voilà.

    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Back to Top