1

我有一个作为主表的数据网格和一个用于详细显示的饼图。我在主表中有一个服务器列表及其 ServerID,如下所示 -

在此处输入图像描述

我的详细信息表是

在此处输入图像描述

当我单击相应的服务器 ID 时,我想在饼图中显示 RAM 的最新值(取决于 RAM_ID)- 已使用和可用。

例如,服务器 1 的值将显示为(来自 Ram_ID) 在此处输入图像描述

服务器 2

在此处输入图像描述

& 用于服务器 3

在此处输入图像描述

我尝试过的,

public override void OnApplyTemplate()
    {
        using (DB_Entities db = new DB_Entities())
        {

          var ramRow = db.UsageRAMs.OrderByDescending(c => c.ID).First();                

          var Ram = new List<UsageRAM>() { new UsageRAM() { name = "Used"  , value = ramRow.Used },
                                          new UsageRAM() { name = "Available" , value = ramRow.Available}};

          this.ramViewSource = (CollectionViewSource)this.FindResource("ramView");
          ramViewSource.Source = Ram;
        }
        base.OnApplyTemplate();
    }

XAML

<customControls:LabeledPieChart x:Name="labeledPieChartRAM" BorderBrush="Transparent" Margin="2,10,35,27" Grid.RowSpan="3" Grid.Column="1">
       <customControls:LabeledPieChart.LegendStyle>
       <Style TargetType="dv:Legend">
        <Setter Property="Width" Value="0" />
       </Style>
     </customControls:LabeledPieChart.LegendStyle>
    <customControls:LabeledPieChart.Series>
   <customControls:LabeledPieSeries x:Name="labeledPieSeriesRAM" 
      ItemsSource="{Binding Source={StaticResource ramView}}"                                                              
      PieChartLabelStyle="{StaticResource pieChartLabelStyle}" 
      PieChartLabelItemTemplate="{StaticResource pieChartLabelDataTemplate}" 
      IndependentValuePath="name" DependentValuePath="value" IsSelectionEnabled="True"
      LabelDisplayMode="ArcMidpoint" />
     </customControls:LabeledPieChart.Series>
    </customControls:LabeledPieChart>

输出

在此处输入图像描述

上述代码的输出显示了详细信息表中的最新值,即它采用 RAM_ID 8 中的值,但在选择时我需要每个服务器的值。如何做到这一点?好心的帮助

4

2 回答 2

1

尝试这样的事情

    //In this query i am grouping the record by ServerID and Selecting ServerID+ Max(Ram_ID )

     using (DB_Entities db = new DB_Entities())
     {
        var lstRamList = (from usgRam in DB.UsageRAMs 
           group usgRam  by new { usgRam.ServerID} 
           into grp
           select
           new
           {
           TMP_ID_ServerID = grp.Key.ServerID,
           TMP_MAX_RAM_ID= grp.Max(x => x.Ram_ID)}); 


 //in this lower list we save all the record from the Db.UsageRAMs where k.ServerID(from above list) == d.ServerID(from Your DB Context) && k.TMP_MAX_RAM_ID == d.Ram_ID
    var lstRAMListFinal = from d in db.UsageRAMs
    where lstRamList.Any(k =>
                        k.TMP_ID_ServerID== d.ServerID  &&
                        k.TMP_MAX_RAM_ID == d.Ram_ID)
   select d;
}
于 2013-04-08T11:01:32.100 回答
0

如果我没记错的话,您可以简单地使用详细信息表中的 RECORD_DATE 列!!!在此处输入图像描述

于 2013-04-08T10:27:39.250 回答