public static string GetChart(FilterJson filterJson) { var chartData = StatisticsBusiness.GetChartData(filterJson); var items = chartData.GroupBy(d => d.Year).ToList(); //var chart = new Chart(width: 800, height: 250, theme: themeChart); var chart = new Chart(width: 1200, height: 375, theme: GetThemeChart()); foreach (var item in chartData) { chart = chart.AddSeries( chartType: "column", xValue: item.Months.Select(m => m.Name).ToList(), //new[] { String.Join(",", item.Months)}, yValues: item.Months.Select(m => m.Sum).ToList(), //new[] { 18000, 14000, 22500 }, name: item.Year.ToString()); } chart = chart.AddLegend(); var bytes = chart.GetBytes("png"); //return File(bytes, "image/png"); string imageBase64 = Convert.ToBase64String(bytes); string imageSrc = string.Format("data:image/png;base64,{0}", imageBase64); return(imageSrc); //var model = StatisticsBusiness.GetChartData(filterJson); //return Json(model); }
private static IEnumerable <StatisticItem> GetChartData(FilterJson filter) { var Bill = EconomyBusiness.GetBills(filter); var result = Bill.GroupBy(x => new { x.DueDate.Year, x.DueDate.Month }) .Select(g => new { Year = g.Key.Year, Month = g.Key.Month, Sum = g.Sum(x => Math.Round(x.Amount, 0)), }) .ToList(); var years = result.GroupBy(x => x.Year).OrderBy(x => x.Key).ToList(); var statistics = new List <StatisticItem>(); foreach (var y in years) { var months = new List <Month>(); // Months for (int monthNo = 1; monthNo < 13; monthNo++) { var sum = (decimal)0; var monthExist = result.Where(d => d.Year.Equals(y.Key) && d.Month.Equals(monthNo)); if (monthExist != null && monthExist.Any()) { sum = monthExist.FirstOrDefault().Sum; } var month = new Month { Number = monthNo, Name = GetMonthName(monthNo), Sum = sum }; months.Add(month); } //var months = result.Where(d => d.Year.Equals(y.Key)) // .Select(x => new Month{ Number = x.Month, Name = GetMonthName(x.Month), Sum = x.Sum }) // .OrderBy(x => x.Number) // .ToList(); statistics.Add(new StatisticItem { Year = y.Key, Months = months }); } return(statistics); }
public static IEnumerable <Bill> GetBills(FilterJson filter) { //var bills = new List<Bill>() using (var ctx = new EconomyContext()) { DateTime fromDate = new DateTime(filter.FromYear, 1, 1); //if (filter.CategoryId.Equals(0) && filter.SubCategoryId.Equals(0) && filter.Description.Equals("0")) //{ var bills = ctx.Bills .Include("Category") .Include("SubCategory") .Include("Payer") .AsQueryable(); //.Where(b => EntityFunctions.CreateDateTime(b.dueDate.Year, b.dueDate.Month, b.dueDate.Day, 0,0,0) > DateTime.Now.AddMonths(4)) //.Where(b => b.CategoryID.Equals(1)) //} bills = bills.Where(b => b.DueDate >= fromDate); if (filter.CategoryId > 0) { bills = bills.Where(b => b.CategoryID.Equals(filter.CategoryId)); } if (filter.SubCategoryId > 0) { bills = bills.Where(b => b.SubCategoryID.Equals(filter.SubCategoryId)); } if (!string.IsNullOrEmpty(filter.Description) && filter.Description != "0") { bills = bills.Where(b => b.Description.Equals(filter.Description)); } return(bills.OrderByDescending(b => b.DueDate).ThenByDescending(b => b.RegDate).ToList()); } }
public Filter(FilterJson json, Schema schema) : this(schema.GetColumn(json.Column), json.Operator, UnpackValue(json.Value)) { }
public static IEnumerable <Bill> GetBills(FilterJson filter) { return(EconomyDataService.GetBills(filter)); }
public JsonResult GetChart(FilterJson filterJson) { var chartImageSrc = StatisticsBusiness.GetChart(filterJson); return(Json(chartImageSrc)); }