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

Xml file in RadChar

1 Answer 52 Views
Chart
This is a migrated thread and some comments may be shown as answers.
jose
Top achievements
Rank 1
jose asked on 31 Jan 2011, 10:03 PM
Hi... everyone.

how to binding xml file in radChar???

1 Answer, 1 is accepted

Sort by
0
Missing User
answered on 03 Feb 2011, 05:21 PM
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>>
Tags
Chart
Asked by
jose
Top achievements
Rank 1
Answers by
Missing User
Share this question
or