private BarChart GenerateBarChart(BudgetLimitGraphModel data)
 {
     // check if  enough data for bar chart
     if (!data.Values.Any())
     {
         return null;
     }
     var barChart = new BarChart
     {
         ComplexData =
         {
             Labels = data.Values.Select(graphData => graphData.Label).ToList(),
             Datasets =
                 new List<ComplexDataset>
                 {
                     this.GenerateComplexData(data.Values.Select(t => t.BudgetLimit).ToList(),
                         ColorGeneratorConstants.Grey),
                     this.GenerateComplexData(data.Values.Select(t => t.ComputedTransaction).ToList(),
                         ColorGeneratorConstants.Red)
                 }
         }
     };
     // graph settings for dynamic charts
     barChart.ChartConfiguration.ScaleBeginAtZero = false;
     barChart.ChartConfiguration.Responsive = true;
     return barChart;
 }
        private async Task<BarChart> CreateChartForBudgetLimits(Guid userId, Currency currency)
        {
            var budgets = await this.GetAccessibleBudgets(userId);
            var transactionFromBudgets = await this.GetTransactionFromBudgets(budgets);
            var graphModels = new List<BudgetWithLimitGraphModel>();
            var complexGraphModel = new BudgetLimitGraphModel
            {
                Values = graphModels,
                Label = DashBoardResource.BudgetTabDescription
            };

            graphModels.AddRange(from budget in budgets
                let budgetTransactions =
                    transactionFromBudgets.ContainsKey(budget.Guid.ToString())
                        ? transactionFromBudgets[budget.Guid.ToString()]
                        : Enumerable.Empty<Transaction>()
                let sumInUserCurrency =
                    budgetTransactions.Select(
                        transaction => Transformation.ChangeCurrencyForNewTransaction(transaction, currency))
                        .Sum(transaction => transaction.Amount)
                select new BudgetWithLimitGraphModel
                {
                    Label = budget.Name,
                    BudgetLimit = budget.Limit,
                    ComputedTransaction = sumInUserCurrency*-1
                });
            return this.GenerateBarChart(complexGraphModel);
        }