C# 如何在WindowsPhone8MVVM中显示包含XML数据的图表
我正在制作一个应用程序,它必须通过在线XML按日期显示汇率。 我用的是麻雀图。当使用示例数据对其进行测试时,图表仅在ChartViewModel函数中正确调用GenerateDatas()方法时显示数据,但在读取asinc XML数据或使用ICommand调用函数时,图表不显示或刷新数据C# 如何在WindowsPhone8MVVM中显示包含XML数据的图表,c#,xaml,windows-phone-8,mvvm,C#,Xaml,Windows Phone 8,Mvvm,我正在制作一个应用程序,它必须通过在线XML按日期显示汇率。 我用的是麻雀图。当使用示例数据对其进行测试时,图表仅在ChartViewModel函数中正确调用GenerateDatas()方法时显示数据,但在读取asinc XML数据或使用ICommand调用函数时,图表不显示或刷新数据 List<CurrencyOfDate> list = new List<CurrencyOfDate>(); foreach (XElement c
List<CurrencyOfDate> list = new List<CurrencyOfDate>();
foreach (XElement c in xmlData.Elements(ns + "Cube").Elements(ns + "Cube"))
list.Add(new CurrencyOfDate()
{
Date = c.Attribute("time").Value,
CurrencyTypes = (from k in xmlData.Elements(ns + "Cube").Elements(ns + "Cube").Elements(ns + "Cube")
select new CurrencyType()
{
Name = k.Attribute("currency").Value,
Value = k.Attribute("rate").Value
}).ToList()
});
FeatList = list;
if (FeatList != null)
{
foreach (var date in FeatList)
{
var x = DateTime.Parse(date.Date);
PickedDate.Add(x);
}
for (int i = 0; i < FeatList.Count; i++)
{
CurList = FeatList[i].CurrencyTypes.ToList();
}
}
MakeChartData();
}
private void MakeChartData()
{
try
{
IsDataLoading = true;
for (int i = 0; i < CurList.Count; i++)
{
var selectedCurrencyRates =
(from c in CurList where c.Name == "GBP" select c).ToList();
foreach (var selRate in selectedCurrencyRates)
{
double parsedFromValue = Double.Parse(selRate.Value);
CalculatedRate.Add(parsedFromValue);
}
}
GenerateDatas();
}
catch (Exception e)
{
IsDataLoading = false;
}
Refresh();
}
private void GenerateDatas()
{
Refresh();
try
{
IsDataLoading = true;
this.Collection.Add(new Model(PickedDate[0], CalculatedRate[0]));
this.Collection.Add(new Model(PickedDate[10], CalculatedRate[10]));
this.Collection.Add(new Model(PickedDate[20], CalculatedRate[20]));
this.Collection.Add(new Model(PickedDate[30], CalculatedRate[30]));
IsDataLoading = false;
}
catch (Exception ex)
{
IsDataLoading = false;
}
}
List List=新列表();
foreach(xmlData.Elements(ns+“Cube”).Elements(ns+“Cube”))中的XElement c)
列表.添加(新的CurrencyOfDate()
{
日期=c.属性(“时间”).值,
CurrencyTypes=(从xmlData.Elements(ns+“Cube”).Elements(ns+“Cube”).Elements(ns+“Cube”).Elements(ns+“Cube”)中的k开始)
选择新的CurrencyType()
{
名称=k.属性(“货币”).值,
值=k.属性(“速率”).值
})托利斯先生()
});
FeatList=列表;
如果(FeatList!=null)
{
foreach(FeatList中的var日期)
{
var x=DateTime.Parse(date.date);
选择日期。添加(x);
}
for(int i=0;i
和xaml:
<chart:SparrowChart x:Name="Chart1" Height="409" Margin="0,0,22,0">
<chart:SparrowChart.Legend>
<chart:Legend Header="EUR/GBP" Height="55" Margin="155,0,172,4" Width="107" />
</chart:SparrowChart.Legend>
<chart:SparrowChart.DataContext>
<viewModels:ChartViewModel/>
</chart:SparrowChart.DataContext>
<chart:SparrowChart.XAxis>
<chart:LinearXAxis/>
</chart:SparrowChart.XAxis>
<chart:SparrowChart.YAxis>
<chart:LinearYAxis/>
</chart:SparrowChart.YAxis>
<chart:LineSeries PointsSource="{Binding Collection}" XPath="X" YPath="Y" IsRefresh="True"/>
</chart:SparrowChart>
问题解决了。这个代码有效。问题是集合是列表类型,但它应该是ObservableCollection