【发布时间】:2020-10-13 23:52:06
【问题描述】:
这是我的控制器:
public ActionResult PPKPIChart()
{
return View();
}
public ActionResult PPKPI()
{
var dt = db.Sales
.Where(ol => ol.SaleId != null)
.GroupBy(ol => ol.PPUsers.Where(p => p.Name != null))
.ToList()
.Select(g => new object[] {
g.Key,
g.Count()
}); ;
return Json(dt, JsonRequestBehavior.AllowGet);
}
这是我的看法:
@section foot {
<script src="https://www.gstatic.com/charts/loader.js"></script>
<script>
google.charts.load('current', { packages: ['corechart'] });
google.charts.setOnLoadCallback(init);
let dt, opt, cht;
function init() {
dt = new google.visualization.DataTable();
// TODO: Data table columns
dt.addColumn('string', 'Name');
dt.addColumn('number', 'KPI');
let style = { bold: true, italic: false, fontSize: 20, color: 'purple' };
opt = {
title: 'Prepress Personnel KPI',
fontName: 'calibri',
fontSize: 14,
titleTextStyle: { fontSize: 20 },
chartArea: {
width: '80%',
height: '70%',
top: 60,
left: 80
},
// TODO: vAxis, hAxis, legend, animation, orientation
vAxis: {
title: 'KPI',
titleTextStyle: style
},
hAxis: {
title: 'Name',
titleTextStyle: style
},
legend: 'none',
animation: {
duration: 500,
startup: true
},
orientation: 'horizontal',
};
cht = new google.visualization.ColumnChart($('#chart')[0]);
$('#reload').click();
}
$('#reload').click(function (e) {
e.preventDefault();
let url = '/Home/PPKPI';
let param = {};
$.getJSON(url, param, function (json) {
dt.removeRows(0, dt.getNumberOfRows());
dt.addRows(json);
cht.draw(dt, opt);
});
});
$('#toggle').click(function (e) {
e.preventDefault();
// TODO: Toggle orientation (horizontal <--> vertical)
opt.orientation = opt.orientation == 'horizontal' ?
'vertical' : 'horizontal';
[opt.vAxis, opt.hAxis] = [opt.hAxis, opt.vAxis];
cht.draw(dt, opt);
});
</script>
这是我的实体框架,具有多对多关系
我想显示条形图,但由于多对多的关系,我不能这样做,尤其是在
GroupBy(ol => ol.PPUsers.Where(p => p.Name != null)) -- > i guess this is the issues behind it.. my query in this line is not working
【问题讨论】:
标签: asp.net asp.net-mvc entity-framework linq