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

Stacked Bar chart in code behind

9 Answers 170 Views
Chart
This is a migrated thread and some comments may be shown as answers.
avinash
Top achievements
Rank 1
avinash asked on 21 Jun 2011, 07:45 AM
Hi,
I want to generate a stacked bar chart dynamically.
Below is the Data what i get in List<>.

Week Data1 Data2 Data3
16/05/2011 11 3 38
12/5/2011 12 1 41
5/5/2011 10 2 43
28/04/2011 4 0 48
17/04/2011 6 1 43
14/04/2011 6 1 45
7/4/2011 6 1 45
28/03/2011 4 1 47
21/03/2011 1 1 46
11/3/2011 1 1 45

Attached is the sample stacked bar from excel. This is what i want to develop.
I want to generate chart in code behind.

Really appreciate if could you help me to solve this?

Regards,
Avi

9 Answers, 1 is accepted

Sort by
0
Evgenia
Telerik team
answered on 21 Jun 2011, 11:48 AM
Hi avinash,

You can follow the code snippet and the explanations provided in this forum post to create StackedBar Series programmatically. To have DateTime values on your XAxis you should follow our help topic.
 
Let me know if you need any further assistance.

Kind regards,
Evgenia
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
avinash
Top achievements
Rank 1
answered on 21 Jun 2011, 01:17 PM

Hi Evgenia,
Thanks for ure quick reply.
I already saw that option. But, the problem is, it is kind of hard coded.

Say, in my example i have 3 series of data. i.e. Data1, data2, data3.

So, as per the example i have to create 3 objects of SeriesMapping.

SeriesMapping seriesMapping = new SeriesMapping { LegendLabel = "Series 1" };
SeriesMapping seriesMapping2 = new SeriesMapping { LegendLabel = "Series 2" }; 
SeriesMapping seriesMapping3 = new SeriesMapping { LegendLabel = "Series 3" }; 

Problem is what if tomorrow my List<> has 6 Data Series.
How could we generate this dynamically.
   
Hope u understood my issue.

Regards,
Avi

0
kris
Top achievements
Rank 1
answered on 24 Jun 2011, 05:28 AM
Hi Avinash

You can use CollectionIndex property in SeriesMapping.

foreach (int index=0;index<in myList.count();index++)
{
SeriesMapping seriesMapping = new SeriesMapping();
seriesMapping.CollectionIndex = index;
seriesMapping.LegendLabel = index.ToString();
seriesMapping.SeriesDefinition = new StackedBarSeriesDefinition();
seriesMapping.SeriesDefinition.ShowItemLabels = false;
seriesMapping.SeriesDefinition.ShowItemToolTips = true;
ItemMapping itemMapping = new ItemMapping();
itemMapping.DataPointMember = DataPointMember.YValue;
itemMapping.FieldName = "TotalValue";
seriesMapping.ItemMappings.Add(itemMapping);
itemMapping = new ItemMapping();
itemMapping.DataPointMember = DataPointMember.XCategory;
itemMapping.FieldName = "FirstListTitle";
seriesMapping.ItemMappings.Add(itemMapping);
}

Regards
Kris
0
Evgenia
Telerik team
answered on 24 Jun 2011, 01:40 PM
Hi Avinash,

You can use the approach mentioned by Kris and for more information about the CollectionIndex property - take a look at our DataBinding to Nested Collections help topic.

Greetings,
Evgenia
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
avinash
Top achievements
Rank 1
answered on 27 Jun 2011, 10:28 AM
Hi Evgenia,
Thanks much.
Wl try that
Regards,
Avi
0
avinash
Top achievements
Rank 1
answered on 05 Jul 2011, 08:14 AM
Hi Kris,

in xaml i have below code. Its a generic one. Im using same chart to generate multiple graphs according to the scenario.

<Grid Style="{StaticResource WrapperStyle}">
               <telerik:RadChart x:Name="radChartRag"/>
</Grid>

Does your approach work here...?

Regards,
Avi
0
Evgenia
Telerik team
answered on 07 Jul 2011, 09:36 AM
Hi Avinash,

We can not understand your frustrations. How does the Grid's WrapperStyle relates to your SeriesMappings? Could you elaborate a bit more on this so that we will be able to help you?

Kind regards,
Evgenia
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
avinash
Top achievements
Rank 1
answered on 07 Jul 2011, 09:50 AM

Hi Evgenia,

Its nothing to do with GRID or its style.
I said in XAML i have only this much.

<telerik:RadChart x:Name="radChartRag"/>

And in code behind also i do not want to hard code series. Like what u showed below. declaring Series1, series2 series3
I wanted a dynamic stacked bar chart.

 

Anyways thanks for your patience. I solved this.

Regards,
Avi

0
Evgenia
Telerik team
answered on 11 Jul 2011, 09:30 AM
Hi Avinash,

I'm glad that you managed to make this work on your own. Let us know if there is anything else we can assist you with.

All the best,
Evgenia
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Chart
Asked by
avinash
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
avinash
Top achievements
Rank 1
kris
Top achievements
Rank 1
Share this question
or