2017-05-08 112 views
0

努力將模型中的數據顯示到劍道條形圖中。 我想如示於下圖中劍道條形圖不顯示數據

enter image description here

控制器返回有效數據,但圖未能正確地顯示數據條形圖來顯示結果。

模型

public class FeeCollectionViewModel 
{ 
    [Key] 
    public int FeeCollectionID { get; set; } 
    public int StudentID { get; set; } 
    public int FeeModeID { get; set; } 
    public int FeeTypeID { get; set; } 
    public string FeeTypeName { get; set; } 
    public double Amount { get; set; } 
    public DateTime CollectionDate { get; set; } 
    } 

這裏是查看

@using Kendo.Mvc.UI 
@using Kendo.Mvc.Extensions 
@{ 
    ViewBag.Title = "Fee Statistics"; 
    Layout = "~/Views/Shared/_Layout.cshtml"; 
} 

<h2>Fee Statistics</h2> 

@(Html.Kendo().Chart<SMS.ViewModels.FeeCollectionViewModel>() 
     .Name("chart") 
     .Title("Today's Collection") 
     .Legend(legend => legend 
     .Position(ChartLegendPosition.Top) 
     ) 
     .DataSource(ds => ds 
      .Read(read => read.Action("TodaysCollection_Read", "FeeCollections")) 
      .Group(group => group.Add(model => model.FeeTypeName)) 
     ) 
     .Series(series => 
     { 
      series.Column(model => model.Amount).Name("Amount Collected"); 
     }) 
     .CategoryAxis(axis => axis 
      .Categories(model => model.FeeTypeName) 
      .Labels(labels => labels.Rotation(-90)) 
      .MajorGridLines(lines => lines.Visible(false)) 
     ) 
     .ValueAxis(axis => axis.Numeric() 
      .Labels(labels => labels.Format("{0:N0}")) 
      .MajorUnit(10000) 
      .Line(line => line.Visible(false)) 
     ) 
     .Tooltip(tooltip => tooltip 
      .Visible(true) 
      .Format("{0:N0}") 
     ) 
) 
+0

如果添加'.AutoBind(true)',它會起作用嗎?還要檢查控制檯中是否有任何相關的javascript錯誤,以及其他控件在視圖或佈局中是否具有ID「chart」。 – zgood

回答

0

劍道走勢不執行GROUPBY總和。我必須在控制器中完成,並將生成的模型傳遞給圖表。

List<FeeCollectionChartViewModel> result = (from f in feeCollections 
               group f by f.FeeTypeName into g 
               select new FeeCollectionChartViewModel() 
                 { 
                  FeeTypeName = g.Key, 
                  Amount = g.Sum(x => x.Amount) 
                 }).ToList(); 
    return Json(result)