我使用Silverlight和Infragistic开发项目作为控件来创建使用数据库数据的数据图表。
我使用论坛建议的Linq,MainPage.xaml.cs
private void studentDomainDataSource_LoadedData(object sender, LoadedDataEventArgs e)
{
if (e.HasError)
{
System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
e.MarkErrorAsHandled();
}
else
{
var ChartData =
(from std in e.Entities
group std by (std as Student).ProgramCode into program
select new ChartData
{
ProgrammName = (program.First() as Student).Programme.ProgramName,
StudentsCount = program.Count()
}).ToList();
xamDataChart1.DataContext = ChartData;
}
}
}
public class ChartData
{
public string ProgrammName { get; set; }
public int StudentsCount { get; set; }
}
这里是MainPage.xaml
<UserControl x:Class="ChartWithRIA.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400" xmlns:riaControls="clr- namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices" xmlns:my="clr-namespace:ChartWithRIA.Web" xmlns:ig="http://schemas.infragistics.com/xaml">
<Grid x:Name="LayoutRoot" Background="White">
<riaControls:DomainDataSource
AutoLoad="True"
d:DesignData="{d:DesignInstance my:Student, CreateList=true}"
Height="0"
LoadedData="studentDomainDataSource_LoadedData"
Name="studentDomainDataSource"
QueryName="GetStudentsQuery"
Width="0">
<riaControls:DomainDataSource.DomainContext>
<my:StudentsProgramDomainContext />
</riaControls:DomainDataSource.DomainContext>
</riaControls:DomainDataSource>
<ig:XamDataChart
Name="xamDataChart1">
<ig:XamDataChart.Axes>
<ig:CategoryXAxis
x:Name="xAxis"
ItemsSource="{Binding}"
Label="{}{ProgrammName}"/>
<ig:NumericYAxis
x:Name="yAxis"/>
</ig:XamDataChart.Axes>
<ig:XamDataChart.Series>
<ig:LineSeries
ItemsSource="{Binding}"
XAxis="{Binding ElementName=xAxis}"
YAxis="{Binding ElementName=yAxis}"
ValueMemberPath="StudentsCount"/>
</ig:XamDataChart.Series>
</ig:XamDataChart>
</Grid>
</UserControl>
构建此解决方案后,没有出现错误,但图表未显示。仅显示布局。 有谁知道我的项目发生了什么或有什么问题? 提前谢谢。