微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

我编写了一个代码来使用 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 举报,一经查实,本站将立刻删除。