1
尽管在互联网上进行了所有搜索。我找不到我的代码有什么问题。 我只是想用我的数据库中的数据填充我的馅饼。这里是我的代码:Kendo饼图仅显示空白区域
数据访问功能: (这是在这里,我得到的所有数据来填充我的馅饼)
public static IEnumerable<PieModel> getTypesForStatistics()
{
var dbo = new UsersContext();
var all = (from a in dbo.Note
select a).ToList();
var results = all.GroupBy(item => item.language.lang)
.Select(g => new PieModel
{
Language = g.Key,
Count = g.Count()
});
return results.ToList();
}
,我已经创建的模型:
public class PieModel
{
public string Language { get; set; }
public int Count { get; set; }
// example : English,4 | Spanish,16 | German, 2 etc
}
在我控制器:
public class StatisticsController : Controller
{
//
// GET: /Statistics/
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult displayChart()
{
var results = Json(DAL.StatisticsAccess.getTypesForStatistics());
return Json(results);
}
}
最后我的看法:
@(Html.Kendo().Chart<DevelopmentNotesProject.Models.PieModel>()
.Name("chart")
.Title(title => title
.Text("")
.Position(ChartTitlePosition.Bottom))
.Legend(legend => legend
.Visible(false)
)
.DataSource(ds => ds.Read(read => read.Action("displayChart", "Statistics")))
.Series(series =>
{
series.Pie(model => model.Count,model => model.Language);
})
.Tooltip(tooltip => tooltip
.Visible(true)
.Format("{0}%")
)
)
在此先感谢您阅读我的代码。