public ActionResult Chart(ChartRequest request) { if (request.StartDate == null) { request.StartDate = DateTime.Now.AddDays(-30); } if (request.EndDate == null) { request.EndDate = DateTime.Now; } if (request.Type != null && request.Type == 2) { return BarChartR(request); } else { request.Type = 1; } if (request.BillType == BillType.None) { request.BillType = BillType.Revenue; } var rest = this._repository.Get( v => v.Status == (int)DataStatus.Normal && v.DataDateTime >= request.StartDate && v.DataDateTime <= request.EndDate && v.User_Id == CurrentUser.CustomerId && v.Type == (int)request.BillType); var g = rest.GroupBy(v => v.Tag_Id); var list = new List<List<object>>(); foreach (var item in g) { var l = new List<object>(2); var sum = item.Sum(v => v.Amount); var t = item.FirstOrDefault(); l.Add(t.Tag.Name); l.Add(sum); list.Add(l); } var r = new List<List<List<object>>>(); r.Add(list); var dto = new ChartDto(); dto.StartDate = request.StartDate.Value; dto.EndDate = request.EndDate.Value; dto.PieVal = list.Count == 0 ? "[[[]]]" : r.ToJson(); dto.Request = request; return View("View2", dto); }
private ActionResult BarChartR(ChartRequest request) { if (request.StartDate == null) { request.StartDate = DateTime.Now.AddDays(-30); } if (request.EndDate == null) { request.EndDate = DateTime.Now; } var rest = this._repository.Get( v => v.Status == (int)DataStatus.Normal && v.DataDateTime >= request.StartDate && v.DataDateTime <= request.EndDate && v.User_Id == CurrentUser.CustomerId); var g = rest.GroupBy(v => v.Tag_Id); var list1 = new List<decimal>(); var list2 = new List<decimal>(); var ticks = new List<string>(); foreach (var item in g) { var l = new List<object>(2); var sum1 = item.Where(v => v.Type == (int)BillType.Expenses).Sum(v => (decimal?)v.Amount) ?? 0; var sum2 = item.Where(v => v.Type == (int)BillType.Revenue).Sum(v => (decimal?)v.Amount) ?? 0; var t = item.FirstOrDefault(); list1.Add(sum1); list2.Add(sum2); ticks.Add(t.Tag.Name); } var r = list1.Count == 0 ? "[[[]]]" : String.Format("[{0},{1}]", list1.ToJson(), list2.ToJson()); var dto = new ChartDto(); dto.StartDate = request.StartDate.Value; dto.EndDate = request.EndDate.Value; dto.PieVal = r; dto.Ticks = ticks.ToJson(); dto.Request = request; return View("View1", dto); }