2017-05-08 114 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)