how to bind xml data to windows phone chart

Posted by Srujana under C# on 7/18/2012 | Points: 10 | Views : 1706 | Status : [Member] | Replies : 4
Hi,

I need to bind web-service returned xml data to windows phone bar chart,

I wrote the following code but the chart is displayed as empty,

can anybody help me in this.

C#:


private void client_GetStudentPerformanceChartCompleted(object sender,ServiceReference1.GetStudentPerformanceChartCompletedEventArgs e)
{
XElement xmlNews = XElement.Parse(e.Result.ToString());

BarSeries series = new BarSeries();

series.ItemsSource = from item in xmlNews.Descendants("SyllabusDetails")
select new Institute
{
Adress = item.Element("SubjectName").Value,

year = item.Element("ResultedMarks").Value
};
}

XAML:

<charting:Chart Foreground="Blue" x:Name="seriesChart" Background="Black">
<charting:BarSeries DependentValueBinding="{Binding year}" IndependentValueBinding="{Binding Adress}" Foreground="Pink" Background="Black" />
</charting:Chart>




Responses

Posted by: Ranjeet_8 on: 7/18/2012 [Member] [MVP] Gold | Points: 25
Posted by: Srujana on: 7/19/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
thanks for giving the reply,I am not using MVVM,
I wrote the code as follows,
class:
public class Chart
{
#region Properties
public string name { get; set; }
public int marks { get; set; }
#endregion
#region Constructors
public Chart(string Name, int Marks)
{
name = Name;
marks = Marks;

}
#endregion


}
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
loginid = StudentPerformance.loginId;
examname = StudentPerformance.examname;
examtypeid = StudentPerformance.examtypeid;
client.GetStudentPerformanceChartCompleted+=new EventHandler<GetStudentPerformanceChartCompletedEventArgs>(client_GetStudentPerformanceChartCompleted);
client.GetStudentPerformanceChartAsync(loginid, examname, examtypeid);


}
private void client_GetStudentPerformanceChartCompleted(object sender,ServiceReference1.GetStudentPerformanceChartCompletedEventArgs e)
{
XElement xmlNews = XElement.Parse(e.Result.ToString());
var results = from item in xmlNews.Descendants("SyllabusDetails")
select new Chart((string)item.Element("SubjectName"),
(int)item.Element("ResultedMarks"));
// BarSeries a = new BarSeries();//when I using this ?I got empty chart
//a.ItemsSource = results;

}
XAML:

<charting:Chart Foreground="Blue" x:Name="seriesChart" Background="Black">
<charting:BarSeries Name="BarChart" ItemsSource="{StaticResource result}" DependentValuePath="marks" IndependentValuePath="name" Foreground="Pink" Background="Black" />
</charting:Chart>

and I got an error in xaml as the resource result could not be resolved.

Srujana, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Srujana on: 7/19/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
I got the solution from this link http://app.eschooltrack.com/Reports/Student_Performance.aspx?pi=bA26ilWlCbBbrQ3CeCw5VA==,
but can I bind multiple dependent values to the single chart with different colors.



Srujana, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tonysolis on: 10/8/2014 [Member] Starter | Points: 25

Up
0
Down
Here's a tutorial I found on MSDN for xml data binding, you can take a look to see if it might help:
http://msdn.microsoft.com/zh-cn/library/ms771368(v=vs.85).aspx

XML data binding to chart in ASP.NET:
http://www.kettic.com/how-to/aspnet-ajax/controls-chart/data-binding-xml/

Srujana, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response