How to bind a xml file to Silverlight Pie Chart

3 posts, 0 answers
  1. Vinod
    Vinod avatar
    2 posts
    Member since:
    Feb 2011

    Posted 02 Feb 2011 Link to this post

    Hi,
         I have a requirement where i need to bind a XML file to a Silver Light Pie Chart and i should be able to configure the series also programatically based on the XML file.

    Regards,

    Vinod.
  2. Vinod
    Vinod avatar
    2 posts
    Member since:
    Feb 2011

    Posted 03 Feb 2011 Link to this post

    Hi,
         Any updates on the thread actually it is stopping me to proceed further
  3. Missing user
    Missing user avatar

    Posted 07 Feb 2011 Link to this post

    Hello Vinod,

    You can read the XML document, retrieve the data and after that bind it to the chart by using Manual Series Mapping.

    Here is a simple XML file:

    <?xml version="1.0" encoding="utf-8" ?>
    <items>
        <item Continent="Europe" Sales="26.92" />
        <item Continent="North America" Sales="17.70" />
        <item Continent="Asia" Sales="27.63" />
        <item Continent="Other" Sales="27.76" />
    </items>

    and you can read it by Linq to XML

    XDocument myXML = XDocument.Load("XMLFile1.xml");
     
    List<SalesItem> salesList =
    (from list in myXML.Descendants("item")
     
    select new SalesItem()
    {
        Continent = list.Attribute("Continent").Value,
        Sales = double.Parse(list.Attribute("Sales").Value),
     
    }).ToList();

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

    this.RadChart1.ItemsSource = salesList;

    and this is a simple example how to populate the data in Pie RadChart

    <telerik:RadChart x:Name="RadChart1">
        ...
        <telerik:RadChart.SeriesMappings>
            <telerik:SeriesMapping>
                <telerik:SeriesMapping.SeriesDefinition>
                    <telerik:PieSeriesDefinition ItemToolTipFormat="#%{P2}">
                        <telerik:PieSeriesDefinition.InteractivitySettings>
                            <telerik:InteractivitySettings HoverScope="Item" SelectionScope="Item" SelectionMode="Single" />
                        </telerik:PieSeriesDefinition.InteractivitySettings>
                    </telerik:PieSeriesDefinition>
                </telerik:SeriesMapping.SeriesDefinition>
                <telerik:SeriesMapping.ItemMappings>
                    <telerik:ItemMapping FieldName="Sales" DataPointMember="YValue" />
                    <telerik:ItemMapping FieldName="Continent" DataPointMember="LegendLabel" />
                </telerik:SeriesMapping.ItemMappings>
            </telerik:SeriesMapping>
        </telerik:RadChart.SeriesMappings>
    </telerik:RadChart>

    Here you can find a demo how to populate data with Pie RadChart:
    http://demos.telerik.com/silverlight/#Chart/FirstLook
    and another examples about reading XML files:
    http://www.telerik.com/help/silverlight/consuming-data-using-xml.html

    I hope this will help you.

    Best wishes,
    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