c# - 在堆积条形图上获取平均值而不是总计?
问题描述
我编写了一个代码来使用 ASP.NET MVC 显示堆积条形图。但是,结果呈现是总计,因为我正在寻找平均值而不是总数。
已处理 = 个人处理的聊天(这工作正常) 团队 = 这应该呈现团队处理的平均聊天(这显示聊天的总数)
因此,为了获得结果,我需要每个月获取用户计数,然后将其除以总数以获得平均值。但是,我无法获得 UserCount,因此我可以将总数除以显示平均值。下面是我的代码
动作方法
public ActionResult Stats()
{
int year = DateTime.Now.Year;
DateTime firstDay = new DateTime(year, 1, 1);
DateTime lastDay = new DateTime(year, 12, 31).AddDays(1).AddSeconds(-1);
var uName = User.Identity.Name;
var result = db.Chats.Where(c => System.Data.Entity.DbFunctions.TruncateTime(c.MSTChatCreatedDateTime) >= firstDay &&
System.Data.Entity.DbFunctions.TruncateTime(c.MSTChatCreatedDateTime) <= lastDay && c.Username == uName)
.Select(x => new { x.MSTChatCreatedDateTime }).ToList().GroupBy(c => new
{
Year = c.MSTChatCreatedDateTime.ToCleanDateTime().Year,
Month = c.MSTChatCreatedDateTime.ToCleanDateTime().ToMonthName()
}).Select(c => new ReportVM
{
Title = string.Format("{0}", c.Key.Month), //chart x Axis value.
ChatCountCreatdDate = c.Count() //chart y Axis value.
}).ToList();
var teamChats = db.Chats.Where(c => System.Data.Entity.DbFunctions.TruncateTime(c.MSTChatCreatedDateTime) >= firstDay &&
System.Data.Entity.DbFunctions.TruncateTime(c.MSTChatCreatedDateTime) <= lastDay).Select(x => new { x.MSTChatCreatedDateTime }).ToList().GroupBy(c => new
{
Year = c.MSTChatCreatedDateTime.ToCleanDateTime().Year,
Month = c.MSTChatCreatedDateTime.ToCleanDateTime().ToMonthName(),
}).Select(c => new ReportVM
{
Title = string.Format("{0}", c.Key.Month), //chart x Axis value.
ChatCountCreatdDate = c.Count() ///chart y Axis value.
}).ToList();
ViewBag.TeamStat = teamChats;
return View(result);
}
附上截图
先感谢您!
解决方案
推荐阅读
- mysql - 为什么我在这里收到 OUTPUT 子句错误?
- javascript - 如何处理 Sails JS 返回的验证消息?
- typescript - 创建引用自身的类型/接口
- reactjs - React-i18next 悬念
- php - Laravel 将 `id` 更改为 `AUTO_INCREMENT`
- laravel - Laravel 分页有问题
- python - conda install packages for all user error 通道不可访问或无效
- haskell - 压缩和计算
- c - C 从 CSV 文件读取每条记录后显示的零
- angular - ngOnChanges 只执行一次