Xml file in RadChar

2 posts, 0 answers
  1. jose
    jose avatar
    7 posts
    Member since:
    Sep 2010

    Posted 31 Jan 2011 Link to this post

    Hi... everyone.

    how to binding xml file in radChar???
  2. Missing user
    Missing user avatar

    Posted 03 Feb 2011 Link to this post

    Hello jose,

    You can read the XML document, retrieve the data and after that bind it to the chart.

    For example this is my xml file:

    <?xml version="1.0" encoding="utf-8" ?>
    <items>
        <item Name="Peter" Age="26" />
        <item Name="Anna" Age="29" />
    </items>

    and I am using Linq to XML to read the data:

    XDocument myXML = XDocument.Load("XMLFile1.xml");
                 
    List<Person> personsList =
    (from person in myXML.Descendants("item")
    select new Person()
    {
        Name = person.Attribute("Name").Value,
        Age = int.Parse(person.Attribute("Age").Value),
             
    }).ToList();

    Here you can find help and another examples about reading XML files:
    http://www.telerik.com/help/silverlight/consuming-data-using-xml.html

    Here you can find examples about populating data in RadChart:
    http://www.telerik.com/help/silverlight/radchart-populating-with-data-overview.html
    http://www.telerik.com/help/silverlight/radchart-populating-with-data-data-binding-with-manual-series-mapping.html

    In this example I'm using Manual Series Mapping and setting the data to the ItemSource:

    radChart.ItemsSource = personsList;

    <telerik:RadChart x:Name="radChart">
        <telerik:RadChart.DefaultView>
            <telerik:ChartDefaultView>
                <telerik:ChartDefaultView.ChartTitle>
                    <telerik:ChartTitle Content="Age Statistic" />
                </telerik:ChartDefaultView.ChartTitle>
            </telerik:ChartDefaultView>
        </telerik:RadChart.DefaultView>
        <telerik:RadChart.SeriesMappings>
            <telerik:SeriesMapping LegendLabel="Age">
                <telerik:SeriesMapping.SeriesDefinition>
                    <telerik:BarSeriesDefinition ShowItemToolTips="True" />
                </telerik:SeriesMapping.SeriesDefinition>
                <telerik:SeriesMapping.ItemMappings>
                    <telerik:ItemMapping DataPointMember="YValue"
                                    FieldName="Age" />
                    <telerik:ItemMapping DataPointMember="XCategory"
                                    FieldName="Name" />
                </telerik:SeriesMapping.ItemMappings>
            </telerik:SeriesMapping>
        </telerik:RadChart.SeriesMappings>
    </telerik:RadChart>

    I hope this will help.

    Regards,
    Polina
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Back to Top