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

How to bind a xml file to Silverlight Pie Chart

2 Answers 126 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Vinod
Top achievements
Rank 1
Vinod asked on 02 Feb 2011, 04:34 PM
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 Answers, 1 is accepted

Sort by
0
Vinod
Top achievements
Rank 1
answered on 03 Feb 2011, 01:40 PM
Hi,
     Any updates on the thread actually it is stopping me to proceed further
0
Missing User
answered on 07 Feb 2011, 02:55 PM
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>>
Tags
Chart
Asked by
Vinod
Top achievements
Rank 1
Answers by
Vinod
Top achievements
Rank 1
Missing User
Share this question
or