This is a migrated thread and some comments may be shown as answers.

Create Stacked Bar Programmatically

1 Answer 230 Views
Chart (obsolete as of Q1 2013)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Michelle
Top achievements
Rank 1
Michelle asked on 08 Aug 2012, 06:10 AM
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.DataBind();
    rcOTDBar.Series[0].Type = ChartSeriesType.StackedBar;
    rcOTDBar.Series[1].Type = ChartSeriesType.StackedBar;
    rcOTDBar.Series[2].Type = ChartSeriesType.StackedBar;
    rcOTDBar.Series[3].Type = ChartSeriesType.StackedBar;
    this.Controls.Add(rcOTDBar);
}

Hi,

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.

1 Answer, 1 is accepted

Sort by
0
Evgenia
Telerik team
answered on 09 Aug 2012, 08:28 AM
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Ă .

Regards,
Evgenia
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
Chart (obsolete as of Q1 2013)
Asked by
Michelle
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
Share this question
or