public ActionResult IncomeByYear() { var income = Income.GetIncome(); var result = from i in income orderby i.Month group i by i.Year into gb select new { _year = gb.Key.ToString(), _income = gb.Sum(n => n.Money) }; var labels = result.Select(n => n._year); var money = result.Select(n => n._income); return(Json(new { labels, money }, JsonRequestBehavior.AllowGet)); }
public ActionResult IncomeByMonth() { var income = Income.GetIncome(); var result = from i in income orderby i.Month group i by i.Month into sp select new { month = sp.Key.ToString(), money = sp.Sum(n => n.Money) }; var labels = result.Select(n => n.month); var money = result.Select(n => n.money); return(Json(new { labels, money }, JsonRequestBehavior.AllowGet)); }