public Chart GetChart(T viewModel, int chartIndex, bool fullSize = false) { Chart _chart = null; List <Entry> entries = new List <Entry>(); List <ChartDataGroup> _chartGroups = new List <ChartDataGroup>(); foreach (var _group in viewModel.ChartDataPack.Charts) { _chartGroups.Add(_group); } ChartDataGroup _selectedGroup = _chartGroups[chartIndex]; switch (_selectedGroup.ChartDisplayType) { case ChartType.Bar: _chart = new BarChart(); break; case ChartType.Line: _chart = new LineChart(); break; case ChartType.Pie: _chart = new DonutChart(); break; } foreach (var item in _selectedGroup.ChartDataItems) { // For now, we'll use a random color SKColor color = ChartUtility.Instance.GetColor(); if (fullSize) { entries.Add(EntryUtility.GetEntry(item.FltValue, color, item.Label, item.ValueLabel)); } else { entries.Add(EntryUtility.GetEntry(item.FltValue, color)); } } _chart.Entries = entries.ToArray(); return(_chart); }
public async Task <Chart> GetChartAsync(T viewModel, int chartIndex, bool fullSize = false) { Chart _chart = null; List <Entry> entries = new List <Entry>(); List <ChartDataGroup> _chartGroups = new List <ChartDataGroup>(); foreach (var _group in viewModel.ChartDataPack.Charts) { _chartGroups.Add(_group); } ChartDataGroup _selectedGroup = _chartGroups[chartIndex]; switch (_selectedGroup.ChartDisplayType) { case ChartType.Bar: _chart = new BarChart(); break; case ChartType.Line: _chart = new LineChart(); break; case ChartType.Pie: _chart = new DonutChart(); break; } foreach (var item in _selectedGroup.ChartDataItems) { SKColor color = !string.IsNullOrEmpty(item.ColorCode) ? SKColor.Parse(item.ColorCode) : ChartUtility.Instance.GetColor(); if (fullSize) { await Task.Run(() => entries.Add(EntryUtility.GetEntry(item.FltValue, color, item.Label, item.ValueLabel))); } else { await Task.Run(() => entries.Add(EntryUtility.GetEntry(item.FltValue, color))); } } _chart.Entries = entries.ToArray(); return(_chart); }
public override IChartDataPack GetChartData() { var dataPack = new ChartDataPack(); var budgetItemsGroup = new ChartDataGroup(); budgetItemsGroup.ChartDisplayType = ChartType.Pie; budgetItemsGroup.ChartDisplayOrder = 0; foreach (var cat in this.BudgetItems.OrderBy(c => c.BudgetedAmount)) { budgetItemsGroup.ChartDataItems.Add(new ChartDataEntry() { FltValue = (float)cat.BudgetedAmount, Label = cat.ItemDescription, ValueLabel = cat.BudgetedAmount.ToString("C"), ColorCode = cat.ColorCode }); } dataPack.Charts.Add(budgetItemsGroup); return(dataPack); }
public override IChartDataPack GetChartData() { var dataPack = new ChartDataPack(); var budgetExpenseGroup = new ChartDataGroup(); budgetExpenseGroup.ChartDisplayType = ChartType.Pie; budgetExpenseGroup.ChartDisplayOrder = 0; foreach (var cat in this.BudgetCategories.Where(c => c.CategoryType == BudgetCategoryType.Expense).OrderBy(c => c.Amount)) { budgetExpenseGroup.ChartDataItems.Add(new ChartDataEntry() { FltValue = (float)cat.Amount, Label = cat.Name, ValueLabel = cat.Amount.ToString("C"), ColorCode = cat.ColorCode }); } dataPack.Charts.Add(budgetExpenseGroup); var budgetIncomeGroup = new ChartDataGroup(); budgetIncomeGroup.ChartDisplayType = ChartType.Pie; budgetIncomeGroup.ChartDisplayOrder = 1; foreach (var cat in this.BudgetCategories.Where(c => c.CategoryType == BudgetCategoryType.Income).OrderBy(c => c.Amount)) { budgetIncomeGroup.ChartDataItems.Add(new ChartDataEntry() { FltValue = (float)cat.Amount, Label = cat.Name, ValueLabel = cat.Amount.ToString("C"), ColorCode = cat.ColorCode }); } dataPack.Charts.Add(budgetIncomeGroup); return(dataPack); }
//IList<AccountRegisterItemViewModel> GetAllTransactions(int accountId) //{ // List<AccountRegisterItemViewModel> _transactions = new List<AccountRegisterItemViewModel>(); // using (UnitOfWork uow = new UnitOfWork(this.dbFilePath)) // { // var _resultsDeposits = Task.Run(() => uow.ge) // } // return _transactions; //} public override IChartDataPack GetChartData() { ChartDataPack chartPack = new ChartDataPack(); ChartDataGroup allCategorizedGroup = new ChartDataGroup(); allCategorizedGroup.ChartDisplayType = ChartType.Bar; allCategorizedGroup.ChartDisplayOrder = 0; //ChartDataGroup incomeCategorizedGroup = new ChartDataGroup(); //incomeCategorizedGroup.ChartDisplayType = ChartType.Bar; //incomeCategorizedGroup.ChartDisplayOrder = 1; //ChartDataGroup spendingCategorizedGroup = new ChartDataGroup(); //spendingCategorizedGroup.ChartDisplayType = ChartType.Bar; //spendingCategorizedGroup.ChartDisplayOrder = 2; List <List <AccountRegisterItemViewModel> > _registerVMsByCategory = new List <List <AccountRegisterItemViewModel> >(); List <AccountRegisterItemViewModel> _allDepositTransactions = new List <AccountRegisterItemViewModel>(); List <AccountRegisterItemViewModel> _allWithdrawalTransactions = new List <AccountRegisterItemViewModel>(); decimal _depositSum = _allDepositTransactions.Sum(t => t.ItemAmount); decimal _withdrawalSum = _allWithdrawalTransactions.Sum(t => t.ItemAmount); foreach (var _accountVM in this.BankAccounts) { _allDepositTransactions.AddRange(_accountVM.AccountRegister.Where(r => r.ItemType == AccountRegisterItemViewModel.AccountItemType.Deposits)); _allWithdrawalTransactions.AddRange(_accountVM.AccountRegister.Where(r => r.ItemType == AccountRegisterItemViewModel.AccountItemType.Withdrawals)); } string _colorCode = string.Empty; List <AccountRegisterItemViewModel> _tempVMList = new List <AccountRegisterItemViewModel>(); // Start with Deposits _registerVMsByCategory = new List <List <AccountRegisterItemViewModel> >(); foreach (var _regVM in _allDepositTransactions.OrderBy(t => t.ObjectColorCode)) { if (_regVM.ObjectColorCode != _colorCode) { if (_tempVMList.Count > 0) { _registerVMsByCategory.Add(_tempVMList); } _colorCode = _regVM.ObjectColorCode; _tempVMList = new List <AccountRegisterItemViewModel>(); } _tempVMList.Add(_regVM); } if (_tempVMList.Count > 0) { _registerVMsByCategory.Add(_tempVMList); } foreach (var _list in _registerVMsByCategory) { foreach (var _listItm in _list) { decimal _itmValue = _listItm.ItemAmount; ChartDataEntry _entry = new ChartDataEntry(); _entry.FltValue = (float)(_itmValue); _entry.Label = "Item Value"; _entry.ValueLabel = _itmValue.ToString("C"); _entry.ColorCode = _listItm.ObjectColorCode; allCategorizedGroup.ChartDataItems.Add(_entry); } //decimal _catValue = _list.Sum(r => r.ItemAmount); //ChartDataEntry _entry = new ChartDataEntry(); //_entry.FltValue = (float)_catValue; //_entry.Label = "Category Total"; //_entry.ColorCode = _list.First().ObjectColorCode; ////incomeCategorizedGroup.ChartDataItems.Add(_entry); //allCategorizedGroup.ChartDataItems.Add(_entry); } // and Withdrawals _registerVMsByCategory = new List <List <AccountRegisterItemViewModel> >(); foreach (var _regVM in _allWithdrawalTransactions.OrderBy(t => t.ObjectColorCode)) { if (_regVM.ObjectColorCode != _colorCode) { if (_tempVMList.Count > 0) { _registerVMsByCategory.Add(_tempVMList); } _colorCode = _regVM.ObjectColorCode; _tempVMList = new List <AccountRegisterItemViewModel>(); } _tempVMList.Add(_regVM); } if (_tempVMList.Count > 0) { _registerVMsByCategory.Add(_tempVMList); } foreach (var _list in _registerVMsByCategory) { foreach (var _listItm in _list) { decimal _itmValue = _listItm.ItemAmount; ChartDataEntry _entry = new ChartDataEntry(); _entry.FltValue = (float)(-1 * _itmValue); _entry.Label = "Item Value"; _entry.ValueLabel = _itmValue.ToString("C"); _entry.ColorCode = _listItm.ObjectColorCode; allCategorizedGroup.ChartDataItems.Add(_entry); } //decimal _catValue = _list.Sum(r => r.ItemAmount); //ChartDataEntry _entry = new ChartDataEntry(); //_entry.FltValue = (float)(-1 * _catValue); //_entry.Label = "Category Total"; //_entry.ColorCode = _list.First().ObjectColorCode; ////spendingCategorizedGroup.ChartDataItems.Add(_entry); //allCategorizedGroup.ChartDataItems.Add(_entry); } chartPack.Charts.Add(allCategorizedGroup); //chartPack.Charts.Add(incomeCategorizedGroup); //chartPack.Charts.Add(spendingCategorizedGroup); //ChartDataGroup accountBalanceGroup = new ChartDataGroup(); //accountBalanceGroup.ChartDisplayType = ChartType.Line; //accountBalanceGroup.ChartDisplayOrder = 0; //int daysInMonth = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month); //// Initialize the time-series chart with an entry for each day in the month //List<ChartDataEntry> _chartData = new List<ChartDataEntry>(); //for (int i = 0; i < daysInMonth; i++) //{ // ChartDataEntry _chartEntry = new ChartDataEntry(); // _chartEntry.ColorCode = "#4CAF50"; // _chartEntry.Label = DateTime.Now.Month.ToString().PadLeft(2, '0') + "/" + (i + 1).ToString().PadLeft(2, '0') + "/" + DateTime.Now.Year.ToString(); // _chartData.Add(_chartEntry); //} //// Find the data for the charts. We want the sum of balances for each day in the graph up to and including //// the current date. //List<AccountRegisterItemViewModel> _masterRegister = new List<AccountRegisterItemViewModel>(); //foreach(BankAccountViewModel _accountVM in this.BankAccounts) //{ // _masterRegister.AddRange(_accountVM.AccountRegister); //} //foreach(ChartDataEntry _chartEntry in _chartData) //{ // int idx = _chartData.IndexOf(_chartEntry); // int day = idx + 1; // string dateToParse = DateTime.Now.Month.ToString() + "/" + day.ToString() + "/" + DateTime.Now.Year.ToString(); // DateTime _testDate = DateTime.Parse(dateToParse); // if (_masterRegister.Any(itm => itm.ItemDate.Date ==_testDate.Date)) // { // decimal _maxEndingBalance = _masterRegister.Where(itm => itm.ItemDate.Date == _testDate.Date).Max(r => r.EndingBalance); // _chartEntry.FltValue = (float)_maxEndingBalance; // _chartEntry.ValueLabel = _maxEndingBalance.ToString("C"); // } // else // { // if (_masterRegister.Count() == 0) // { // _chartEntry.FltValue = (float)this.BankAccounts.Max(b => b.CurrentBalance); // _chartEntry.ValueLabel = _chartEntry.FltValue.ToString("C"); // } // else // { // //_chartEntry.FltValue = (float)0M; // //_chartEntry.ValueLabel = string.Format("{0:C}", 0); // if (day <= DateTime.Now.Day) // { // _chartEntry.FltValue = idx > 0 ? _chartData[idx - 1].FltValue : (float)0M; // _chartEntry.ValueLabel = _chartEntry.FltValue.ToString("C"); // } // else // { // _chartEntry.FltValue = (float)0M; // _chartEntry.ValueLabel = _chartEntry.FltValue.ToString("C"); // } // } // } // accountBalanceGroup.ChartDataItems.Add(_chartEntry); //} //chartPack.Charts.Add(accountBalanceGroup); return(chartPack); }
public override IChartDataPack GetChartData() { ChartDataPack chartPack = new ChartDataPack(); ChartDataGroup allCategorizedGroup = new ChartDataGroup(); allCategorizedGroup.ChartDisplayOrder = 0; allCategorizedGroup.ChartDisplayType = ChartType.Bar; List <List <AccountRegisterItemViewModel> > _registerVMsByCategory = new List <List <AccountRegisterItemViewModel> >(); List <AccountRegisterItemViewModel> _allDepositTransactions = new List <AccountRegisterItemViewModel>(); List <AccountRegisterItemViewModel> _allWithdrawalTransactions = new List <AccountRegisterItemViewModel>(); decimal _depositSum = _allDepositTransactions.Sum(t => t.ItemAmount); decimal _withdrawalSum = _allWithdrawalTransactions.Sum(t => t.ItemAmount); _allDepositTransactions.AddRange(this.AccountRegister.ToList().Where(r => r.ItemType == AccountRegisterItemViewModel.AccountItemType.Deposits)); _allWithdrawalTransactions.AddRange(this.AccountRegister.ToList().Where(r => r.ItemType == AccountRegisterItemViewModel.AccountItemType.Withdrawals)); string _colorCode = string.Empty; List <AccountRegisterItemViewModel> _tempVMList = new List <AccountRegisterItemViewModel>(); // Start with Deposits _registerVMsByCategory = new List <List <AccountRegisterItemViewModel> >(); foreach (var _regVM in _allDepositTransactions.OrderBy(t => t.ItemDate)) { _tempVMList.Add(_regVM); } foreach (var _regVM in _allWithdrawalTransactions.OrderBy(t => t.ItemDate)) { _tempVMList.Add(_regVM); } //if (_tempVMList.Count > 0) //{ // _registerVMsByCategory.Add(_tempVMList); //} //foreach (var _list in _registerVMsByCategory) //{ // foreach (var _listItm in _list) // { // decimal _itmValue = _listItm.ItemAmount; // ChartDataEntry _entry = new ChartDataEntry(); // _entry.FltValue = (float)(_itmValue); // _entry.Label = "Item Value"; // _entry.ValueLabel = _itmValue.ToString("C"); // _entry.ColorCode = _listItm.ObjectColorCode; // allCategorizedGroup.ChartDataItems.Add(_entry); // } // //decimal _catValue = _list.Sum(r => r.ItemAmount); // //ChartDataEntry _entry = new ChartDataEntry(); // //_entry.FltValue = (float)_catValue; // //_entry.Label = "Deposit Value"; // //_entry.ValueLabel = _catValue.ToString("C"); // //_entry.ColorCode = _list.First().ObjectColorCode; // ////incomeCategorizedGroup.ChartDataItems.Add(_entry); // //allCategorizedGroup.ChartDataItems.Add(_entry); //} foreach (var _itm in _tempVMList.OrderBy(vm => vm.ItemDate)) { decimal _itmValue = _itm.ItemAmount; ChartDataEntry _entry = new ChartDataEntry(); _entry.FltValue = _itm.ItemType == AccountRegisterItemViewModel.AccountItemType.Deposits ? (float)(_itmValue) : (float)(-1 * _itmValue); _entry.Label = "Item Value"; _entry.ValueLabel = _itmValue.ToString("C"); _entry.ColorCode = _itm.ObjectColorCode; allCategorizedGroup.ChartDataItems.Add(_entry); } // and Withdrawals //_registerVMsByCategory = new List<List<AccountRegisterItemViewModel>>(); //foreach (var _regVM in _allWithdrawalTransactions.OrderBy(t => t.ItemDate)) //{ // //if (_regVM.ObjectColorCode != _colorCode) // //{ // // if (_tempVMList.Count > 0) // // { // // _registerVMsByCategory.Add(_tempVMList); // // } // // _colorCode = _regVM.ObjectColorCode; // // _tempVMList = new List<AccountRegisterItemViewModel>(); // //} // _tempVMList.Add(_regVM); //} //if (_tempVMList.Count > 0) //{ // _registerVMsByCategory.Add(_tempVMList); //} //foreach (var _list in _registerVMsByCategory) //{ // foreach(var _listItm in _list.OrderBy(vm => vm.ItemDate)) // { // decimal _itmValue = _listItm.ItemAmount; // ChartDataEntry _entry = new ChartDataEntry(); // _entry.FltValue = (float)(-1 * _itmValue); // _entry.Label = "Item Value"; // _entry.ValueLabel = _itmValue.ToString("C"); // _entry.ColorCode = _listItm.ObjectColorCode; // allCategorizedGroup.ChartDataItems.Add(_entry); // } // //decimal _catValue = _list.Sum(r => r.ItemAmount); // //ChartDataEntry _entry = new ChartDataEntry(); // //_entry.FltValue = (float)(-1 * _catValue); // //_entry.Label = "Category Value"; // //_entry.ValueLabel = // //_entry.ColorCode = _list.First().ObjectColorCode; // ////spendingCategorizedGroup.ChartDataItems.Add(_entry); // //allCategorizedGroup.ChartDataItems.Add(_entry); //} chartPack.Charts.Add(allCategorizedGroup); //List<List<AccountRegisterItemViewModel>> _registerVMsByCategory = new List<List<AccountRegisterItemViewModel>>(); //string _colorCode = string.Empty; //List<AccountRegisterItemViewModel> _tempVMList = new List<AccountRegisterItemViewModel>(); //foreach (var _regVM in this.AccountRegister.OrderBy(t => t.ObjectColorCode)) //{ // if (_regVM.ObjectColorCode != _colorCode) // { // if (_tempVMList.Count > 0) // { // _registerVMsByCategory.Add(_tempVMList); // } // _colorCode = _regVM.ObjectColorCode; // _tempVMList = new List<AccountRegisterItemViewModel>(); // } // _tempVMList.Add(_regVM); //} //if (_tempVMList.Count > 0) //{ // _registerVMsByCategory.Add(_tempVMList); //} //foreach (var _list in _registerVMsByCategory) //{ // decimal _catValue = _list.Sum(r => r.ItemAmount); // ChartDataEntry _entry = new ChartDataEntry(); // _entry.FltValue = (float)_catValue; // _entry.Label = "Category Total"; // _entry.ColorCode = _list.First().ObjectColorCode; // chartByCategoryGroup.ChartDataItems.Add(_entry); //} //chartPack.Charts.Add(chartByCategoryGroup); return(chartPack); }