我是asp.net mvc3的新手,并在Chart for for MVC3剃须刀的stackoverflow中阅读了很多帖子。
但是,我无法为此创建图表。基本上这是我的SQL查询
SELECT COUNT(RequestStatus) AS Expr1, RequestStatus
FROM Request
GROUP BY RequestStatus
到目前为止,在我的控制视图中,这是我的代码:
public ActionResult RequestReport()
{
var result = from p in db.Requests
group p by p.RequestStatus into pgroup
let count = pgroup.Count()
orderby count
select new { Count = count, RequestStatus = pgroup.Key }.ToString();
var x = new [] {result};
Chart chart = new Chart(600, 400)
.AddSeries(yValues: x , yFields:"Count")
.AddTitle("Request Statistic");
this.ViewBag.Chart = chart;
return View();
}
和 在视图中:
@ViewBag.Chart.Write()
请帮我解决这个问题。我找不到一个简单的教程。
我对控制器中的代码做了一些更改。
using (var db = new ITAMMVCDBEntities())
{
var rs = db.Requests.GroupBy(o=>o.RequestStatus).ToList();
var result = from o in db.Requests
group o by o.RequestStatus
into g
select new
{
result = g.Count()
};
Chart chart = new Chart(600, 400)
.AddSeries(
xValue: rs.Select(x=>x.Key).ToArray() ,
yValues: result.ToArray()
)
.AddTitle("Request Statistic");
this.ViewBag.Chart = chart;
return View();
}
现在我在运行
时收到此错误消息Series data points do not support values of type <>f__AnonymousType1`1[System.Int32] only values of these types can be used: Double, Decimal, Single, int, long, uint, ulong, String, DateTime, short, ushort.
我认为我的xValue没问题,因为它按组显示 但问题populationg yValue将显示每个组的值