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

Bar chart dynamic series

1 Answer 96 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Arun Kumar
Top achievements
Rank 2
Arun Kumar asked on 19 Jul 2011, 04:42 PM
Hi All,

I have the following data (City, Description, Counts) returned from database

City,            Description,      Counts
Beirut Desc - 1 10000
Beirut Desc - 2 100
Beirut Desc - 3 5
Beijing   Desc - 1 90
Japan Desc - 3 2
Singapore   Desc - 2 2300
.....

Here not always all city will load. Based on some filters data is populated.

I want to show Description in xcategory and Counts in YValue and city will be series and legend value.

I am using group description based on city but its not giving correct result. Also I tried to add series based on cities but that also not working (showing all description as same value (i.e) first series value). 

How do I create bar chart for this?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Missing User
answered on 22 Jul 2011, 06:37 PM
Hello Arun Kumar,

You can use SeriesMapping.GroupingSettings to group the data by City. You also need to set the Description field as XCategory DataPointMember. For example:
<telerik:RadChart x:Name="radChart">
    <telerik:RadChart.SeriesMappings>
        <telerik:SeriesMapping>
            <telerik:SeriesMapping.SeriesDefinition>
                <telerik:BarSeriesDefinition />
            </telerik:SeriesMapping.SeriesDefinition>
            <telerik:SeriesMapping.GroupingSettings>
                <telerik:GroupingSettings ShouldCreateSeriesForLastGroup="True">
                    <telerik:GroupingSettings.GroupDescriptors>
                        <telerik:ChartGroupDescriptor Member="City"/>
                    </telerik:GroupingSettings.GroupDescriptors>
                </telerik:GroupingSettings>
            </telerik:SeriesMapping.GroupingSettings>
            <telerik:SeriesMapping.ItemMappings>
                <telerik:ItemMapping DataPointMember="YValue" FieldName="Counts" />
                <telerik:ItemMapping DataPointMember="XCategory" FieldName="Description" />
            </telerik:SeriesMapping.ItemMappings>
        </telerik:SeriesMapping>
    </telerik:RadChart.SeriesMappings>
</telerik:RadChart>

and the code-behind:
List<MyDataItem> data = new List<MyDataItem>()
{
    new MyDataItem() {City = "Beirut", Counts = 10000, Description = "1"},
    new MyDataItem() {City = "Beirut", Counts = 100, Description = "2"},
    new MyDataItem() {City = "Beirut", Counts = 5, Description = "3"},
    new MyDataItem() {City = "Beijing", Counts = 90, Description = "1"},
    new MyDataItem() {City = "Japan", Counts = 2, Description = "3"},
    new MyDataItem() {City = "Singapore", Counts = 2300, Description = "2"}
};
 
radChart.ItemsSource = data;
public class MyDataItem
{
    public string City { get; set; }
    public string Description { get; set; }
    public double Counts { get; set; }
}

For additional information on grouping functionality, please refer to the following help topic:
http://www.telerik.com/help/silverlight/radchart-features-grouping-and-aggregation.html

I hope that this helps.

Kind regards,
Polina
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
Arun Kumar
Top achievements
Rank 2
Answers by
Missing User
Share this question
or