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
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
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" };
Hope u understood my issue.SeriesMapping seriesMapping3 = new SeriesMapping { LegendLabel = "Series 3" };
Problem is what if tomorrow my List<> has 6 Data Series.
How could we generate this dynamically.
Regards,
Avi
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
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
Thanks much.
Wl try that
Regards,
Avi
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
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!
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
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!