示例#1
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            BarChartViewModel viewModel = await Task.Run(() =>
            {
                DateTime now                    = DateTime.Now;
                BarChartViewModel vm            = new BarChartViewModel();
                vm.MinDate                      = DateTime.MaxValue;
                vm.MaxDate                      = DateTime.MinValue;
                List <BankAccount> bankAccounts = _myFinanceService.GetBankAccounts(User.GetUserId());

                bankAccounts.Where(x => x.IsVisible).ToList().ForEach(bankAccount =>
                {
                    var categories          = _myFinanceService.GetCategories(User.GetUserId());
                    DateTime lastPaymentDay = FindLastPaymentDay(now);
                    bankAccount.Movements   = _myFinanceService.GetBankAccountMovements(User.GetUserId(), bankAccount.Id, lastPaymentDay, now);

                    foreach (var selectedCategory in categories)
                    {
                        bankAccount.Movements.GroupBy(x => x.BankAccount).ToList().ForEach(x =>
                        {
                            if (x.Key.Movements.Where(r => r.Categories != null).SelectMany(q => q.Categories).Any())
                            {
                                var items = x.Where(e => e.Categories != null && e.Categories.Any(r => r.CategoryId == selectedCategory.Id));

                                AddItemIfAnyItem(bankAccount, vm, selectedCategory, items);
                            }
                        });
                    }
                });

                return(vm);
            });

            return(View(viewModel));
        }
        public JsonResult ServerBarChartsData()
        {
            string[] _categories = { "Apples", "Oranges", "Pears", "Grapes", "Bananas" };

            List <ChartSerieViewModel> series = new List <ChartSerieViewModel>();

            for (int i = 0; i < 3; i++)
            {
                decimal   d      = 2 + i;
                decimal[] _datas = { d, 3, 4, 7, d };

                ChartSerieViewModel lineChartSerieViewModel = new ChartSerieViewModel();
                lineChartSerieViewModel.SeriesName  = "John : " + i;
                lineChartSerieViewModel.SeriesDatas = _datas;

                series.Add(lineChartSerieViewModel);
            }

            var model = new BarChartViewModel();

            model.TitleText       = "Stacked column chart";
            model.XAxisCategories = _categories;
            model.YAxisTitleText  = "Total fruit consumption";
            model.Series          = series.ToArray();

            return(Json(model, JsonRequestBehavior.AllowGet));
        }
        public ActionResult RefreshBarChart(DateTime start, DateTime end, string nutrient)
        {
            var                     viewModel = new BarChartViewModel();
            List <string>           categories;
            List <string>           names;
            List <List <decimal?> > data;

            if (nutrient.ToLower() == "macronutrient ratios")
            {
                categories = new List <string> {
                    string.Empty
                };
                names = _chartServices.GetMacronutrientRatioCategories();
                data  = _chartServices.CalculateMacronutrientRatioData(start, end, UserId);
            }
            else
            {
                categories = _chartServices.GetProductNames(start, end, UserId);
                names      = _chartServices.GetMacronutrientTitle(nutrient);
                data       = _chartServices.CalculateMacronutrientByProduct(start, end, new List <string> {
                    nutrient
                }, UserId);

                //CalculateTotals(ref viewModel);
                //CalculateRDA(ref viewModel, nutrient);
            }

            viewModel.Categories = categories;
            viewModel.MapToSeries(data, names);


            return(Json(viewModel, JsonRequestBehavior.AllowGet));
        }
示例#4
0
        public ActionResult RefreshBarChart(DateTime start, DateTime end, string nutrient)
        {
            User user = _userServices.GetUser(User.Identity.Name);

            List <Day>     days      = _foodItemServices.GetDays(start, end, user.Id).ToList();
            List <Product> products  = _productServices.GetProducts(days).ToList();
            var            viewModel = new BarChartViewModel();

            if (nutrient.ToLower() == "totalenergy")
            {
                viewModel.BarNames   = _chartServices.GetTotalEnergyCategories();
                viewModel.ChartTitle = _chartServices.GetTitle(nutrient);
                viewModel.BarData    = _chartServices.CalculateTotalEnergyData(days, products);
            }
            else if (nutrient.ToLower() == "alcohol")
            {
                viewModel.BarNames   = _chartServices.GetBarNames(days);
                viewModel.ChartTitle = _chartServices.GetTitle(nutrient);
                viewModel.BarData    = _chartServices.CalculateAlcoholByProduct(days, products);
            }
            else
            {
                viewModel.BarNames   = _chartServices.GetBarNames(days);
                viewModel.ChartTitle = _chartServices.GetTitle(nutrient);
                viewModel.BarData    = _chartServices.CalculateNutrientByProduct(days, products, nutrient);
            }

            return(Json(viewModel, JsonRequestBehavior.AllowGet));
        }
示例#5
0
        public CategoryExpensesViewModel(CategoryExpensesSummary summary, List <Categories> availableCategories, Categories selectedCategory, DateRangeViewModel dateRangeVM) : this(availableCategories, dateRangeVM)
        {
            categoryId   = selectedCategory.Id;
            categoryName = selectedCategory.Name;

            if (summary.GroupedExpenses.Count() == 0)
            {
                ChartHeader = $"Nie znaleziono ani jednego wydatku w kategorii {categoryName}";
                return;
            }

            ChartHeader       = $"{categoryName} ({summary.GroupedExpenses.Sum(x => x.TotalPricesSum)}zł)";
            BarChartViewModel = new BarChartViewModel()
            {
                Type   = "horizontalBar",
                Labels = summary.GroupedExpenses.Select(x => x.Name ?? string.Empty).ToList(),
                Values = summary.GroupedExpenses.Select(x => x.TotalPricesSum).ToList(),
                Height = summary.GroupedExpenses.Count() * 20 + 30,
                LegendSquaresHexColors = new List <string>()
                {
                    categoryHexBgColor, subCategoriesHexBgColor
                },
                LegendDescriptions = new List <string>()
                {
                    $"Wydatek należący do kategorii {categoryName}", $"Wydatek należący do jednej z podkategorii kategorii {categoryName}"
                },
            };

            foreach (var item in summary.GroupedExpenses)
            {
                AddChartBgColor(item);
                AddChartTootlip(item);
            }
        }
示例#6
0
        private BarChartViewModel GetBarChart()
        {
            BarDataSet dataset = new BarDataSet()
            {
                label           = "Buy",
                data            = new int[] { 65, 59, 80, 81, 56, 55, 40 },
                backgroundColor = "#42A5F5",
                borderColor     = "borderColor"
            };

            BarDataSet dataset2 = new BarDataSet()
            {
                label           = "Borrow",
                data            = new int[] { 28, 48, 40, 19, 86, 27, 90 },
                backgroundColor = "#9CCC65",
                borderColor     = "7CB342"
            };

            BarChartViewModel vm = new BarChartViewModel()
            {
                labels   = new string[] { "January", "February", "March", "April", "May", "June", "July" },
                datasets = new BarDataSet[] { dataset, dataset2 }
            };

            return(vm);
        }
示例#7
0
        /// <summary>
        /// The UpdateBarModelsData.
        /// </summary>
        /// <param name="barChartModel">The barChartModel<see cref="BarChartViewModel"/>.</param>
        /// <param name="barValuesModels">The barValuesModels<see cref="IList{BarValuesModel}"/>.</param>
        /// <param name="positionIndex">The positionIndex<see cref="int"/>.</param>
        public static void UpdateBarModelsData(this BarChartViewModel barChartModel, IList <BarValuesModel> barValuesModels, int positionIndex)
        {
            var barModels = barChartModel.BarModels;

            if (barModels.Count != barValuesModels.Count)
            {
                throw new ArgumentException($"{nameof(UpdateBarModelsData)} Error: {nameof(barModels)} and {nameof(barValuesModels)} count is not equal.");
            }
            var min = double.MaxValue;
            var max = double.MinValue;

            for (var i = 0; i < barModels.Count; i++)
            {
                var barModel    = barModels[i];
                var valuesModel = barValuesModels[i];
                barModel.IsSuspended = true;
                barModel.Index       = valuesModel.RankSteps[positionIndex];
                var offset      = barChartModel.SortDirection == System.ComponentModel.ListSortDirection.Descending ? barModel.Index - valuesModel.RanksInterpolated[positionIndex] : valuesModel.RanksInterpolated[positionIndex] - barModel.Index;
                var indexOffset = offset * barModel.BarContainerHeight;

                /// Prevent the first winner is drawn outside the area.
                if (barModel.Index == barModels.Count - 1 && indexOffset < 0)
                {
                    indexOffset = 0;
                }

                barModel.IndexOffset = indexOffset;
                barModel.BarOpacity  = 1 - (Math.Sin(offset.Abs() * Math.PI) * 0.7);
                var value = valuesModel.ValuesInterpolated[positionIndex];
                if (value < 0)
                {
                    value = 0;
                }

                barModel.Value = valuesModel.ValuesInterpolated[positionIndex];
                if (min > barModel.Value)
                {
                    min = barModel.Value;
                }

                if (max < barModel.Value)
                {
                    max = barModel.Value;
                }
            }

            if (min >= max || barChartModel.IsVisibleRangeFromZero)
            {
                min = 0;
            }

            var visibleRange = new RangeDouble(min, max);

            for (var i = 0; i < barModels.Count; i++)
            {
                barModels[i].VisibleRange = visibleRange;
                barModels[i].IsSuspended  = false;
            }
        }
        /// <summary>
        /// The Test.
        /// </summary>
        /// <param name="testWindow">The testWindow<see cref="Window"/>.</param>
        protected override void Test(MetroWindow testWindow)
        {
            var globalData = new GlobalData {
                MainWindow = testWindow
            };
            var viewModel = new BarChartViewModel(globalData);
            var view      = new BarChartView {
                DataContext = viewModel
            };

            this.GenerateDummyData(viewModel);
            WindowFactory.CreateAndShow(view, testWindow);
        }
        /// <summary>
        /// The GenerateDummyData.
        /// </summary>
        /// <param name="viewModel">The viewModel<see cref="BarChartViewModel"/>.</param>
        private void GenerateDummyData(BarChartViewModel viewModel)
        {
            viewModel.Title    = "Bar Chart Test App";
            viewModel.Subtitle = "Show Bar Chart with Dummy Data";
            var n     = 5;
            var range = new RangeDouble(0, 1000);

            for (var i = 0; i < n; i++)
            {
                var model = new BarModel {
                    Index = i, Name = $"Bar Test {i}", Value = (n - i) * (range.Length() / n), VisibleRange = range
                };
                viewModel.BarModels.Add(model);
            }
        }
示例#10
0
        public List <BarChartViewModel> InitBarChart(string empid)
        {
            var storeProcedureName = "[dbo].[Init_BarChart]";
            var result             = _dbContext.Database.SqlQuery <BarChartViewModel>(
                $"{storeProcedureName} @empid",
                new SqlParameter("@empid", empid)
                ).ToList();
            var list = new List <BarChartViewModel>();

            foreach (var i in result)
            {
                var ord = new BarChartViewModel();
                ord.month    = i.month;
                ord.business = i.business;
                ord.profit   = i.profit;
                list.Add(ord);
            }
            return(list);
        }
示例#11
0
        private void AddItemIfAnyItem(BankAccount bankAccount, BarChartViewModel vm, Category selectedCategory, IEnumerable <BankAccountMovement> items)
        {
            if (items.Any())
            {
                var amout = -items.Sum(q => q.Amount);

                if (amout > 0)
                {
                    FindDates(vm, items.Min(q => q.MovementDate), items.Max(q => q.MovementDate));

                    vm.Items.Add(new BarChartItemViewModel()
                    {
                        Label = selectedCategory.Name,
                        Color = bankAccount.Color,
                        Value = amout,
                        Group = bankAccount.Bank.ToString()
                    });
                }
            }
        }
示例#12
0
        public IEnumerable <BarChartViewModel> GetBarChartData(int year)
        {
            var stats = this.Statistics.Find(s => s.Year == year).ToList();

            ICollection <BarChartViewModel> models = new List <BarChartViewModel>();

            foreach (var stat in stats)
            {
                BarChartViewModel model = new BarChartViewModel
                {
                    HitsCount       = stat.HitsCount,
                    SubscribesCount = stat.SubscribesCount,
                    Month           = LanguageTranslator.TranslateNumBgMonth(stat.Month)
                };

                models.Add(model);
            }

            return(models);
        }
        public BarChartViewModel GetAssesmentCompareChartInfo(ReportFilterViewModel obj)
        {
            BarChartViewModel model = new BarChartViewModel();

            return(model);
        }
示例#14
0
 public BarChartPage()
 {
     InitializeComponent();
     BindingContext = new BarChartViewModel();
 }
        public BarChartViewModel Getdatabycandidatename(string BatchName, string CandidateName, int ReviewId)
        {
            BarChartViewModel model = new BarChartViewModel();
            int BatchId             = 0;
            var data = _context.tblPerformanceParameterTypeResultMasters.Where(w => !w.tblPerformanceParameterResultMasters.FirstOrDefault().IsNotApplicable).AsQueryable();

            if (BatchName != null)
            {
                BatchId = GetBatchIdByName(BatchName);
                data    = data.Where(w => w.tblPerformanceEntryMaster.BatchId == BatchId);
            }
            var PieChartInfo = data;

            if (CandidateName != null)
            {
                data = data.Where(t => (t.tblPerformanceEntryMaster.AddmissionMaster.Fname + " " + t.tblPerformanceEntryMaster.AddmissionMaster.Lname) == CandidateName || t.tblPerformanceEntryMaster.AddmissionMaster.Fname == CandidateName);
            }
            if (ReviewId > 0)
            {
                data = data.Where(t => t.tblPerformanceEntryMaster.ReviewId == ReviewId);
            }

            var result = data.Select(item => new ParameterTypeInfoList
            {
                BatchId             = _context.AddmissionDetails.Where(a => a.AddmissionMaster.RegistrationNo == item.tblPerformanceEntryMaster.RegistrationNo).FirstOrDefault().BatchId,
                ParameterType       = item.tblParameterType.Name,
                PerformanceMasterId = item.tblPerformanceMasterId,
                RegNo             = item.tblPerformanceEntryMaster.RegistrationNo,
                ParameterInfoList = item.tblPerformanceParameterResultMasters.Select(ob => new ParameterInfoList
                {
                    Rating         = ob.Rating,
                    Remarks        = ob.tblParameterList.Name,
                    TblParameterId = ob.tblParameterId,
                    ReviewName     = ob.tblPerformanceParameterTypeResultMaster.tblPerformanceEntryMaster.tblReviewMaster.Name
                }).ToList(),
                ReviewId = item.tblPerformanceEntryMaster.ReviewId
            }).ToList();

            if (result.Count() > 0)
            {
                model.RegistraionNo = result.FirstOrDefault().RegNo;
            }

            decimal[] BarY = null;
            decimal[] BarX = null;
            if (result.Count > 0)
            {
                model.BarChartLbl = result.Select(d => d.ParameterType).Distinct().ToArray();
                BarY = new decimal[model.BarChartLbl.Length];
                BarX = new decimal[model.BarChartLbl.Length];
            }
            else
            {
                model.BarChartLbl = _context.tblParameterTypes.Where(p => p.IsActive).Select(d => d.Name).Distinct().ToArray();
                BarY = new decimal[model.BarChartLbl.Length];
                BarX = new decimal[model.BarChartLbl.Length];
            }

            if (ReviewId == 0)
            {
                model.SubchartString = JsonConvert.SerializeObject(result.GroupBy(x => x.ParameterType, (name, items) => new
                {
                    Name = name,
                    list = items.Select(sa => sa.ParameterInfoList).ToList()
                }).ToList());

                var result1 = result.Where(r => r.ReviewId == 2).ToList();
                var result2 = result.Where(r => r.ReviewId == 3).ToList();
                for (int i = 0; i < model.BarChartLbl.Count(); i++)
                {
                    int res1Count = result1.Where(r => r.ParameterType == model.BarChartLbl[i]).Count();
                    int res2Count = result2.Where(r => r.ParameterType == model.BarChartLbl[i]).Count();
                    int res1Sum   = result1.Where(r => r.ParameterType == model.BarChartLbl[i]).Sum(s => s.ParameterInfoList.Sum(p => p.Rating));
                    int res2Sum   = result2.Where(r => r.ParameterType == model.BarChartLbl[i]).Sum(s => s.ParameterInfoList.Sum(p => p.Rating));
                    BarY[i] = res1Count > 0 ? Math.Round(GetBarChartPercentage(res1Count, res1Sum), 2) : 0;
                    BarX[i] = res2Count > 0 ? Math.Round(GetBarChartPercentage(res2Count, res2Sum), 2) : 0;
                }
            }
            else if (ReviewId == 2)
            {
                var result1 = result.Where(r => r.ReviewId == 2).ToList();
                model.SubchartString = JsonConvert.SerializeObject(result1.GroupBy(x => x.ParameterType, (name, items) => new
                {
                    Name = name,
                    list = items.Select(sa => sa.ParameterInfoList).ToList()
                }).ToList());
                for (int i = 0; i < model.BarChartLbl.Count(); i++)
                {
                    int res1Count = result1.Where(r => r.ParameterType == model.BarChartLbl[i]).Count();
                    int res1Sum   = result1.Where(r => r.ParameterType == model.BarChartLbl[i]).Sum(s => s.ParameterInfoList.Sum(p => p.Rating));
                    BarY[i] = res1Count > 0 ? Math.Round(GetBarChartPercentage(res1Count, res1Sum), 2) : 0;
                    //BarY[i] = result1.Count() > 0 ? GetPercentage(result1[i].ParameterInfoList.Count, result1[i].ParameterInfoList.Sum(s => s.Rating)) : 0;
                }
                BarX = null;
            }
            else if (ReviewId == 3)
            {
                var result2 = result.Where(r => r.ReviewId == 3).ToList();
                model.SubchartString = JsonConvert.SerializeObject(result2.GroupBy(x => x.ParameterType, (name, items) => new
                {
                    Name = name,
                    list = items.Select(sa => sa.ParameterInfoList).ToList()
                }).ToList());
                for (int i = 0; i < model.BarChartLbl.Count(); i++)
                {
                    int res2Count = result2.Where(r => r.ParameterType == model.BarChartLbl[i]).Count();
                    int res2Sum   = result2.Where(r => r.ParameterType == model.BarChartLbl[i]).Sum(s => s.ParameterInfoList.Sum(p => p.Rating));
                    BarX[i] = res2Count > 0 ? Math.Round(GetBarChartPercentage(res2Count, res2Sum), 2) : 0;
                }
                BarY = null;
            }
            model.DataY = BarY;
            model.DataX = BarX;

            // Do nut chart
            var     PieChartData   = PieChartInfo.Where(p => p.tblPerformanceEntryMaster.ReviewId == 3).ToList();
            decimal HighPercentage = 0;
            decimal MidPercentage  = 0;
            decimal LowPercentage  = 0;

            decimal[] PieData = new decimal[3];
            List <ParameterListViewModel> ParameterListModel = new List <ParameterListViewModel>();

            if (PieChartData.Count > 0)
            {
                foreach (var m in PieChartData)
                {
                    ParameterListModel.Add(m.tblPerformanceParameterResultMasters.Select(s => new ParameterListViewModel
                    {
                        Rating = s.Rating
                    }).FirstOrDefault());
                }
                var High = ParameterListModel.Where(h => h.Rating == 3).ToList();
                var Mid  = ParameterListModel.Where(h => h.Rating == 2).ToList();
                var Low  = ParameterListModel.Where(h => h.Rating == 1).ToList();

                HighPercentage = High.Count > 0 ? GetPercentage(High.Count, High.Sum(h => h.Rating)) : 0;
                MidPercentage  = Mid.Count > 0 ? GetPercentage(Mid.Count, Mid.Sum(h => h.Rating)) : 0;
                LowPercentage  = Low.Count > 0 ? GetPercentage(Low.Count, Low.Sum(h => h.Rating)) : 0;
            }
            PieData[0]         = HighPercentage;
            PieData[1]         = MidPercentage;
            PieData[2]         = LowPercentage;
            model.PieChartData = PieData;
            return(model);
        }
示例#16
0
        public ActionResult GalleriesSchedulesCompare()
        {
            List <Gallery> galleires = caller.ListOfAllGalleries();

            foreach (var item in galleires)
            {
                item.schedule = caller.ListOfAllSchedules(item.id);
            }
            Gallery gallery     = galleires.Find(g => g.id == 2);
            Gallery galleryBeta = galleires.Find(g => g.id == 3);
            int     count1_17   = 0;
            int     count1_18   = 0;
            int     count1_19   = 0;
            int     count2_17   = 0;
            int     count2_18   = 0;
            int     count2_19   = 0;

            //    int z = gallery.schedule.Count(e => { DateTime t = (DateTime)e.startDate} == 2017);
            foreach (var item in gallery.schedule)
            {
                DateTime t = (DateTime)item.startDate;
                if (t.Year == 2017)
                {
                    count1_17++;
                }
                if (t.Year == 2018)
                {
                    count1_18++;
                }
                if (t.Year == 2019)
                {
                    count1_19++;
                }
            }
            foreach (var item in galleryBeta.schedule)
            {
                DateTime t = (DateTime)item.startDate;
                if (t.Year == 2017)
                {
                    count2_17++;
                }
                if (t.Year == 2018)
                {
                    count2_18++;
                }
                if (t.Year == 2019)
                {
                    count2_19++;
                }
            }

            BarChartViewModel a = new BarChartViewModel();
            BarChartViewModel b = new BarChartViewModel();
            BarChartViewModel c = new BarChartViewModel();

            a.a = count1_17;
            a.b = count2_17;
            a.y = "2017";
            b.a = count1_18;
            b.b = count2_18;
            b.y = "2018";
            c.a = count1_19;
            c.b = count2_19;
            c.y = "2019";
            List <BarChartViewModel> bar = new List <BarChartViewModel>();

            bar.Add(a);
            bar.Add(b);
            bar.Add(c);
            var json = JsonConvert.SerializeObject(bar);

            ViewBag.data = json;
            JavaScriptSerializer jss = new JavaScriptSerializer();

            string output = jss.Serialize(bar);

            string demo = output.Replace("\"", "");

            ViewBag.jss = demo;

            return(View(bar));
        }
示例#17
0
        // GET: Statistics
        public ActionResult Index()
        {
            int scale = 50;
            List <LineChartViewModel> stat      = new List <LineChartViewModel>();
            List <Gallery>            galleires = caller.ListOfAllGalleries().OrderByDescending(o => o.maxCapacity).ToList();

            if (scale < galleires.First().maxCapacity)
            {
                int sections = (int)galleires.First().maxCapacity / scale;
                int oldScale = 0;
                int tmpScale = scale;
                for (int i = 0; i < sections + 1; i++)
                {
                    //  if (galleires.Count(g => oldScale <= g.maxCapacity && g.maxCapacity < tmpScale)!=0)
                    // {
                    LineChartViewModel tmp = new LineChartViewModel();
                    tmp.x = tmpScale;
                    tmp.y = galleires.Count(g => oldScale <= g.maxCapacity && g.maxCapacity < tmpScale);
                    stat.Add(tmp);
                    // }//

                    oldScale = tmpScale;
                    tmpScale = tmpScale + scale;
                }
            }

            JavaScriptSerializer jss2 = new JavaScriptSerializer();

            string output3 = jss2.Serialize(stat);

            string demo3 = output3.Replace("\"", "");

            float somme  = 0;
            float somme2 = 0;
            float M      = 0;
            float V      = 0;
            float Ec     = 0;

            foreach (var item in galleires)
            {
                somme  = somme + (float)item.surface;
                somme2 = somme2 + (float)item.surface * (float)item.surface;
            }
            M            = somme / galleires.Count;
            V            = somme2 / galleires.Count - M * M;
            Ec           = (float)Math.Sqrt(V);
            ViewBag.M    = M;
            ViewBag.V    = V;
            ViewBag.Ec   = Ec;
            ViewBag.line = demo3;
            /******************************************/
            foreach (var item in galleires)
            {
                item.schedule = caller.ListOfAllSchedules(item.id);
            }
            Gallery gallery     = galleires.Find(g => g.id == 2);
            Gallery galleryBeta = galleires.Find(g => g.id == 3);
            int     count1_17   = 0;
            int     count1_18   = 0;
            int     count1_19   = 0;
            int     count2_17   = 0;
            int     count2_18   = 0;
            int     count2_19   = 0;

            //    int z = gallery.schedule.Count(e => { DateTime t = (DateTime)e.startDate} == 2017);
            foreach (var item in gallery.schedule)
            {
                DateTime t = (DateTime)item.startDate;
                if (t.Year == 2017)
                {
                    count1_17++;
                }
                if (t.Year == 2018)
                {
                    count1_18++;
                }
                if (t.Year == 2019)
                {
                    count1_19++;
                }
            }
            foreach (var item in galleryBeta.schedule)
            {
                DateTime t = (DateTime)item.startDate;
                if (t.Year == 2017)
                {
                    count2_17++;
                }
                if (t.Year == 2018)
                {
                    count2_18++;
                }
                if (t.Year == 2019)
                {
                    count2_19++;
                }
            }

            BarChartViewModel a = new BarChartViewModel();
            BarChartViewModel b = new BarChartViewModel();
            BarChartViewModel c = new BarChartViewModel();

            a.a = count1_17;
            a.b = count2_17;
            a.y = "2017";
            b.a = count1_18;
            b.b = count2_18;
            b.y = "2018";
            c.a = count1_19;
            c.b = count2_19;
            c.y = "2019";
            List <BarChartViewModel> bar = new List <BarChartViewModel>();

            bar.Add(a);
            bar.Add(b);
            bar.Add(c);
            var json = JsonConvert.SerializeObject(bar);

            JavaScriptSerializer jss = new JavaScriptSerializer();

            string output = jss.Serialize(bar);

            string demo = output.Replace("\"", "");

            ViewBag.jss = demo;

            /**********************/
            //  List<Gallery> galleires = caller.ListOfAllGalleries();

            List <schedule>   schedules = new List <schedule>();
            List <DonutChart> stat2     = new List <DonutChart>();
            DonutChart        donut     = new DonutChart();
            DonutChart        donut2    = new DonutChart();
            DonutChart        donut3    = new DonutChart();

            foreach (var item in galleires)
            {
                foreach (var tmp in item.schedule)
                {
                    schedules.Add(tmp);
                }
            }
            //Holiday,Event,Renovations,Other

            donut.value  = schedules.Count(s => s.type == "Holiday");
            donut.label  = "Holiday";
            donut2.value = schedules.Count(s => s.type == "Event");
            donut2.label = "Event";
            donut3.value = schedules.Count(s => s.type == "Renovations");
            donut3.label = "Renovations";
            donut3.value = schedules.Count(s => s.type == "Other");
            donut3.label = "Other";

            stat2.Add(donut);
            stat2.Add(donut2);
            stat2.Add(donut3);
            //JavaScriptSerializer jss = new JavaScriptSerializer();

            /*string output = jss.Serialize(stat);
             *
             * string demo = output.Replace("\"", "");*/

            ViewBag.dot = stat2;

            /*********************/
            return(View());
        }
        //============================================================================================
        public BarChartViewModel GetBarChartRegistrationData(ReportFilterViewModel filterModel)
        {
            var data = _context.RegistrationMasters.Select(item => new
            {
                EnteredDate = item.RegistrationDate,
                RegistartionNo = item.RegistartionNo,
                CourseId = item.CourseId
            }).AsQueryable();

            if (!string.IsNullOrWhiteSpace(filterModel.CourseId))
            {
                var courseArr = filterModel.CourseId.Split(',').Select(Int32.Parse).ToList();
                if (courseArr.Count > 0)
                    data = data.Where(t => courseArr.Any(c => c == t.CourseId));
            }

            BarChartViewModel model = new BarChartViewModel();
            if (filterModel.Month > 0)
            {
                if (filterModel.Year > 0)
                    data = data.Where(d => d.EnteredDate.Value.Year == filterModel.Year);
                var feeInfo = data.Where(d => d.EnteredDate.Value.Month == filterModel.Month)
                    .GroupBy(x => x.EnteredDate.Value.Day, (name, items) => new
                    {
                        Day = name,
                        Amount = items.Count() * 1000
                    }).OrderBy(o => o.Day).ToList();
                decimal[] BarY = new decimal[DateTime.DaysInMonth(filterModel.Year, filterModel.Month)];
                for (int i = 1; i <= DateTime.DaysInMonth(filterModel.Year, filterModel.Month); i++)
                {
                    var a = feeInfo.Where(n => n.Day == i).FirstOrDefault();
                    if (a != null)
                        BarY[i - 1] = a.Amount;
                    else
                        BarY[i - 1] = 0;
                }
                int daysMonth = DateTime.DaysInMonth(filterModel.Year, filterModel.Month);
                string[] days = new string[daysMonth];
                for (int i = 1; i <= daysMonth; i++)
                    days[i - 1] = i.ToString();
                model.BarChartLbl = days;
                model.DataY = BarY;
            }
            else if (filterModel.Year > 0)
            {
                var feeInfo = data.Where(d => d.EnteredDate.Value.Year == filterModel.Year)
                  .GroupBy(x => x.EnteredDate.Value.Month, (name, items) => new
                  {
                      Month = name,
                      Amount = items.Count() * 1000
                  }).OrderBy(o => o.Month).ToList();
                decimal[] BarY = new decimal[12];
                for (int i = 1; i <= 12; i++)
                {
                    var a = feeInfo.Where(n => n.Month == i).FirstOrDefault();
                    if (a != null)
                        BarY[i - 1] = a.Amount;
                    else
                        BarY[i - 1] = 0;
                }
                model.BarChartLbl = new string[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
                model.DataY = BarY;
            }
            else
            {
                var feeInfo = data.GroupBy(x => x.EnteredDate.Value.Year, (name, items) => new
                {
                    Year = name,
                    Amount = items.Count() * 1000
                }).OrderBy(o => o.Year).ToList();
                decimal[] BarY = new decimal[3];
                string[] chLbl = new string[3];
                int j = 1;
                for (int i = (DateTime.Now.Year - 2); i <= DateTime.Now.Year; i++)
                {
                    chLbl[j - 1] = i.ToString();
                    var a = feeInfo.Where(n => n.Year == i).FirstOrDefault();
                    if (a != null)
                        BarY[j - 1] = a.Amount;
                    else
                        BarY[j - 1] = 0;
                    j++;
                }
                model.BarChartLbl = chLbl;
                model.DataY = BarY;
            }
            return model;
        }
        public BarChartViewModel GetBarChartData(ReportFilterViewModel filterModel)
        {
            var data = _context.FeeCollections.Where(f => f.IsActive)
                .Select(item => new
                {
                    EnteredDate = item.EnteredDate,
                    Amount = item.PartWisePayments.Count > 0 ? item.PartWisePayments.Sum(p => p.Amount).Value : item.Amount,
                    AdmInfo = _context.AddmissionDetails.Where(a => a.AddmissionMaster.RegistrationNo == item.FeePaymentDetail.FeeDetail.RegistrationNo).Select(s => new
                    {
                        BatchId = s.BatchId,
                        State = s.AddmissionMaster.AddressDetails.FirstOrDefault().PerState,
                        city = s.AddmissionMaster.AddressDetails.FirstOrDefault().PerCity
                    }).FirstOrDefault(),
                    InstallMentNo = item.InstallmentMasterId,
                    CourseId = item.FeePaymentDetail.FeeDetail.FeeTypeDetail.CourseId
                }).AsQueryable();

            if (filterModel.InstallmentNo > 0)
                data = data.Where(w => w.InstallMentNo == filterModel.InstallmentNo);

            if (!string.IsNullOrWhiteSpace(filterModel.CourseId))
            {
                var courseArr = filterModel.CourseId.Split(',').Select(Int32.Parse).ToList();
                if (courseArr.Count > 0)
                    data = data.Where(t => courseArr.Any(c => c == t.CourseId));
            }
            if (!string.IsNullOrWhiteSpace(filterModel.BatchId))
            {
                var batchArr = filterModel.BatchId.Split(',').Select(Int32.Parse).ToList();
                if (batchArr.Count > 0)
                    data = data.Where(t => batchArr.Any(c => c == t.AdmInfo.BatchId));
            }
            if (!string.IsNullOrEmpty(filterModel.State))
            {
                data = data.Where(x => x.AdmInfo.State == filterModel.State);
                if (!string.IsNullOrEmpty(filterModel.City))
                    data = data.Where(x => x.AdmInfo.city == filterModel.City);
            }
            BarChartViewModel model = new BarChartViewModel();
            if (filterModel.Month > 0)
            {
                if (filterModel.Year > 0)
                    data = data.Where(d => d.EnteredDate.Year == filterModel.Year);
                var feeInfo = data.Where(d => d.EnteredDate.Month == filterModel.Month)
                    .GroupBy(x => x.EnteredDate.Day, (name, items) => new
                    {
                        Day = name,
                        Amount = items.Sum(i => i.Amount)
                    }).OrderBy(o => o.Day).ToList();
                decimal[] BarY = new decimal[DateTime.DaysInMonth(filterModel.Year, filterModel.Month)];
                for (int i = 1; i <= DateTime.DaysInMonth(filterModel.Year, filterModel.Month); i++)
                {
                    var a = feeInfo.Where(n => n.Day == i).FirstOrDefault();
                    if (a != null)
                        BarY[i - 1] = a.Amount;
                    else
                        BarY[i - 1] = 0;
                }
                int daysMonth = DateTime.DaysInMonth(filterModel.Year, filterModel.Month);
                string[] days = new string[daysMonth];
                for (int i = 1; i <= daysMonth; i++)
                    days[i - 1] = i.ToString();
                model.BarChartLbl = days;
                model.DataY = BarY;
            }
            else if (filterModel.Year > 0)
            {
                var feeInfo = data.Where(d => d.EnteredDate.Year == filterModel.Year)
                  .GroupBy(x => x.EnteredDate.Month, (name, items) => new
                  {
                      Month = name,
                      Amount = items.Sum(i => i.Amount)
                  }).OrderBy(o => o.Month).ToList();
                decimal[] BarY = new decimal[12];
                for (int i = 1; i <= 12; i++)
                {
                    var a = feeInfo.Where(n => n.Month == i).FirstOrDefault();
                    if (a != null)
                        BarY[i - 1] = a.Amount;
                    else
                        BarY[i - 1] = 0;
                }
                model.BarChartLbl = new string[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
                model.DataY = BarY;
            }
            else
            {
                var feeInfo = data.GroupBy(x => x.EnteredDate.Year, (name, items) => new
                {
                    Year = name,
                    Amount = items.Sum(i => i.Amount)
                }).OrderBy(o => o.Year).ToList();
                decimal[] BarY = new decimal[3];
                string[] chLbl = new string[3];
                int j = 1;
                for (int i = (DateTime.Now.Year - 2); i <= DateTime.Now.Year; i++)
                {
                    chLbl[j - 1] = i.ToString();
                    var a = feeInfo.Where(n => n.Year == i).FirstOrDefault();
                    if (a != null)
                        BarY[j - 1] = a.Amount;
                    else
                        BarY[j - 1] = 0;
                    j++;
                }
                model.BarChartLbl = chLbl;
                model.DataY = BarY;
            }
            return model;
        }
示例#20
0
 private void FindDates(BarChartViewModel vm, DateTime minDate, DateTime maxDate)
 {
     vm.MinDate = vm.MinDate > minDate ? minDate : vm.MinDate;
     vm.MaxDate = vm.MaxDate < maxDate ? maxDate : vm.MaxDate;
 }