【发布时间】:2021-05-17 03:20:17
【问题描述】:
如何显示当月每周的数据?使用我当前的代码,我只能显示上周、本月或本周的数据。但我正在努力编写一个可以显示当前月份数据的代码,按周显示。
例子
Week1 = QAScore 94%(Average)
Week2 = 95%
Week3 = 90%
Week4 = 91%
模型类如下
public String Title { get; set; }
public DateTime? CreatdDate { get; set; }
public int ChatCountCreatdDate { get; set; }
动作
public ActionResult DisplayChart()
{
//initial data.
//List<Chat> orderlist = new List<Chat>();
//based on the year month and week, group the order, and get the weekly report.
var result = db.Chats.ToList().GroupBy(c => new
{
Year = c.MSTChatCreatedDateTime.ToCleanDateTime().Year,
Month = c.MSTChatCreatedDateTime.ToCleanDateTime().Month,
WeekofMonth = c.MSTChatCreatedDateTime.ToCleanDateTime().GetWeekOfMonth()
}).Select(c => new ReportVM
{
Title = string.Format("{0}/{1}/Week{2}", c.Key.Year, c.Key.Month, c.Key.WeekofMonth), //chart x Axis value.
ChatCountCreatdDate = c.Count() //chart y Axis value.
}).ToList();
//return the data to the view.
return View(result);
}
查看
@model List<TicketTool.Models.VM.ReportVM>
@{
ViewBag.Title = "DisplayChart";
}
<meta name="viewport" content="width=device-width" />
<h2>DisplayChart</h2>
@{
var chart = new Chart(width: 500, height: 500, themePath: "MyTheme.xml")
.AddTitle("Order Distribution")
.AddSeries("Order", chartType: "Column",
xValue: Model, xField: "Title",
yValues: Model, yFields: "ChatCountCreatdDate")
.Write();
}
以上是我展示数据的操作方法。
【问题讨论】:
-
请不要将这样的随机单词大写。读这样的文字很烦人。
标签: asp.net-mvc asp.net-core asp.net-mvc-4