在堆积条形图上获取平均值而不是总计?

问题描述

我编写了一个代码来使用 ASP.NET MVC 显示堆积条形图。但是,渲染结果是 Total,因为我正在寻找平均值而不是总计数。

已处理 = 由个人处理的聊天(这行得通) 团队 = 这应该呈现团队处理的平均聊天数(这显示了聊天总数)

因此,为了获得结果,我需要每个月获取用户计数,然后将其除以总数以获得平均值。但是,我只是无法获得 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}",//chart x Axis value.
ChatCountCreatdDate = c.Count()  ///chart y Axis value.
}).ToList();

ViewBag.TeamStat = teamChats;


            

return View(result);

}

附上截图

Char

先谢谢你!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)