我正在尝试将我的数据映射到 ViewModel 中的图表。我设置绑定,填充对象,但由于某种原因没有显示数据。您能否验证我做错了什么?谢谢!
查看模型文件:
QueryableCollectionView qcv;
public QueryableCollectionView Groups
{
get
{
return qcv;
}
set
{
qcv = value;
}
}
public RevenueChartViewModel()
{
List<Revenue> list = new List<Revenue>
{
new Revenue{Rev = 10, Category = 1, Date = DateTime.Today.AddDays(1)},
new Revenue{Rev = 20, Category = 1, Date = DateTime.Today.AddDays(3)},
new Revenue{Rev = 30, Category = 2, Date = DateTime.Today.AddDays(6)},
};
qcv = new QueryableCollectionView(list);
qcv.GroupDescriptors.Add(new GroupDescriptor() { Member = "Category" });
}
XAML:
<UserControl x:Class="FrontEnd.RevenueChart"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:FrontEnd"
mc:Ignorable="d" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" HorizontalAlignment="Stretch"
xmlns:telerikChart="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Charting"
xmlns:telerikCharting="clr-namespace:Telerik.Windows.Controls.Charting;assembly=Telerik.Windows.Controls.Charting"
xmlns:telerikControls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls">
<UserControl.DataContext>
<local:RevenueChartViewModel/>
</UserControl.DataContext>
<Grid>
<telerikChart:RadChart x:Name="radChart1">
<telerik:Series DataSeries="{Binding Groups}">
</telerik:Series>
<telerik:RadChart.SeriesMappings>
<telerikCharting:SeriesMapping LegendLabel="Product Sales">
<telerikCharting:SeriesMapping.SeriesDefinition>
<telerikCharting:AreaSeriesDefinition/>
</telerikCharting:SeriesMapping.SeriesDefinition>
<telerikCharting:SeriesMapping.ItemMappings>
<telerikCharting:ItemMapping DataPointMember="XCategory" FieldName="Date"/>
<telerikCharting:ItemMapping DataPointMember="YValue" FieldName="Rev"/>
</telerikCharting:SeriesMapping.ItemMappings>
</telerikCharting:SeriesMapping>
</telerik:RadChart.SeriesMappings>
</telerikChart:RadChart>
</Grid>
</UserControl>