private void Init()
        {
            finalBalance = SumIncomes - SumOutcomes;

            if (finalBalance > 0)
            {
                tvStatus.Text = GetString(Resource.String.we_still_have_money);
                tvFinalBalance.SetTextColor(Context.GetColorStateList(Resource.Color.text_color_blue));
                tvFinalBalance.Text = $"+{finalBalance.ToCurrency()}";
            }
            else
            {
                tvStatus.Text = GetString(Resource.String.We_are_broke_now);
                tvFinalBalance.SetTextColor(Context.GetColorStateList(Resource.Color.text_color_red));
                tvFinalBalance.Text = finalBalance.ToCurrency();
            }

            tvIncome.Text  = $"+{SumIncomes.ToCurrency()}";
            tvOutcome.Text = $"-{SumOutcomes.ToCurrency()}";

            barChart.Description.Enabled  = false;
            barChart.Legend.Enabled       = false;
            barChart.AxisRight.Enabled    = false;
            barChart.AxisLeft.Enabled     = false;
            barChart.AxisLeft.AxisMinimum = 0;
            barChart.XAxis.Position       = XAxis.XAxisPosition.Bottom;
            barChart.XAxis.SetDrawGridLines(false);
            barChart.XAxis.Granularity = 1;
            barChart.SetExtraOffsets(0, 0, 0, 10);
            barChart.SetScaleEnabled(false);

            var labels = new List <string>()
            {
                GetString(Resource.String.income),
                GetString(Resource.String.outcome)
            };

            var barGroup = new List <BarEntry>()
            {
                new BarEntry(0, SumIncomes / 1000f),
                new BarEntry(1, SumOutcomes / 1000f)
            };

            var barDataSet = new BarDataSet(barGroup, null);

            barDataSet.SetColors(new int[] { Resource.Color.income_color, Resource.Color.outcome_color }, Context);
            barDataSet.SetDrawValues(false);

            barChart.XAxis.ValueFormatter = new IndexAxisValueFormatter(labels);
            barChart.XAxis.TextColor      = ContextCompat.GetColor(Context, Resource.Color.text_color_blue);
            barChart.XAxis.TextSize       = Resources.GetDimension(Resource.Dimension.text_size_normal);
            barChart.Data = new BarData(barDataSet);;
            barChart.Invalidate();
        }
Esempio n. 2
0
        private void SetChartData()
        {
            if (!ViewModel.StatisticItems.Any())
            {
                return;
            }

            var chart = FindViewById <BarChart>(Resource.Id.chart);

            var dataSetdExpenses = new BarDataSet(new List <BarEntry> {
                new BarEntry(0, (float)ViewModel.StatisticItems[0].Value)
            }, ViewModel.StatisticItems[0].Label);

            dataSetdExpenses.SetColors(Resources.GetColor(Resource.Color.color_income, Theme));

            var dataSetIncome = new BarDataSet(new List <BarEntry> {
                new BarEntry(1, (float)ViewModel.StatisticItems[1].Value)
            }, ViewModel.StatisticItems[1].Label);

            dataSetIncome.SetColors(Resources.GetColor(Resource.Color.color_expense, Theme));

            var dataSetRevenue = new BarDataSet(new List <BarEntry> {
                new BarEntry(2, (float)ViewModel.StatisticItems[2].Value)
            }, ViewModel.StatisticItems[2].Label);

            dataSetRevenue.SetColors(Resources.GetColor(Resource.Color.color_revenue, Theme));

            var barData = new BarData(dataSetdExpenses, dataSetIncome, dataSetRevenue)
            {
                BarWidth = 0.9f
            };

            chart.Data = barData;
            chart.Description.Enabled = false;
            chart.SetPinchZoom(false);
            chart.SetFitBars(true);

            var legend = chart.Legend;

            legend.TextSize    = 12f;
            legend.Orientation = Legend.LegendOrientation.Horizontal;
            legend.SetDrawInside(true);
            legend.VerticalAlignment   = Legend.LegendVerticalAlignment.Bottom;
            legend.HorizontalAlignment = Legend.LegendHorizontalAlignment.Left;
            legend.XEntrySpace         = 7f;
            legend.YEntrySpace         = 0;
            legend.YOffset             = 0f;

            chart.Invalidate();
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            mView        = inflater.Inflate(Resource.Layout.ChartAllTablesDialog, container, false);
            chartSuccess = mView.FindViewById <BarChart>(Resource.Id.chartAllTablesDialog);

            dicOfDataSets = new Dictionary <string, List <BarEntry> >();

            List <StatsTables> searchedTable = (from table in listStatsTables
                                                where table.big_deviation.Contains("NO", StringComparison.OrdinalIgnoreCase)
                                                select table).ToList <StatsTables>();

            foreach (StatsTables row in searchedTable)
            {
                if (!listTableNames.Contains(row.table_name))
                {
                    listTableNames.Add(row.table_name);
                }
            }

            int counter = 0;

            foreach (string table in listTableNames)
            {
                barEntry = new List <BarEntry>();
                foreach (StatsTables item in searchedTable)
                {
                    if (table == item.table_name)
                    {
                        barEntry.Add(new BarEntry(counter, item.diff_last_trans));
                        counter++;
                    }
                }
                dicOfDataSets.Add(table, barEntry);
            }

            BarData data = new BarData();

            int[] chartColors  = { Color.ParseColor("#005571"), Color.ParseColor("#227691"), Color.ParseColor("#86B1C6"), Color.ParseColor("#BCD4E0"), Color.ParseColor("#FDB813"), Color.ParseColor("#FFC54E"), Color.ParseColor("#FFD27C"), Color.ParseColor("#FFE6B9") };
            int   counterColor = 0;

            foreach (KeyValuePair <string, List <BarEntry> > dicDataSet in dicOfDataSets)
            {
                dataSet = new BarDataSet(dicDataSet.Value, dicDataSet.Key);
                dataSet.SetColors(chartColors[counterColor]);
                data.AddDataSet(dataSet);
                counterColor++;
            }

            XAxis xAxis = chartSuccess.XAxis;

            xAxis.SetCenterAxisLabels(false);
            xAxis.SetDrawLabels(false);
            xAxis.Position = XAxis.XAxisPosition.BottomInside;
            xAxis.SetDrawGridLines(false);
            xAxis.SetAvoidFirstLastClipping(true);
            xAxis.XOffset = 10;

            Legend l = chartSuccess.Legend;

            l.VerticalAlignment   = Legend.LegendVerticalAlignment.Top;
            l.HorizontalAlignment = Legend.LegendHorizontalAlignment.Right;
            l.Orientation         = Legend.LegendOrientation.Vertical;
            l.WordWrapEnabled     = true;
            l.SetDrawInside(true);

            chartSuccess.Data = data;
            chartSuccess.AxisRight.SetDrawLabels(false);
            chartSuccess.XAxis.SetDrawLabels(false);
            chartSuccess.AnimateXY(3000, 3000);

            chartSuccess.Description.Enabled = true;
            chartSuccess.Description.Text    = "Tables without big deviation";

            chartSuccess.Invalidate();

            return(mView);
        }
        private void UpdatePaidView(string year)
        {
            var sumMoneyPaidByYear = moneyStates.Sum(x => x.IsPaid &&
                                                     (x.MoneyModel.Time.Year.ToString().Equals(year) ||
                                                      year.Equals(Total))
                ? x.MoneyModel.Amount
                : 0);

            tvPaid.Text = sumMoneyPaidByYear.ToCurrency();

            if (sumMoneyPaidByYear == 0)
            {
                barChart.Visibility = ViewStates.Invisible;
            }
            else
            {
                barChart.Visibility = ViewStates.Visible;

                var labels   = new List <string>();
                var barGroup = new List <BarEntry>();

                if (year.Equals(Total))
                {
                    var moneyYears = moneyStates
                                     .GroupBy(x => x.MoneyModel.Time.Year)
                                     .OrderBy(x => x.Key)
                                     .Select(x => new
                    {
                        lable = x.Key.ToString(),
                        value = x.Sum(y => y.IsPaid ? y.MoneyModel.Amount : 0)
                    });

                    labels = moneyYears.Select(x => x.lable).ToList();

                    barGroup = moneyYears
                               .Select((x, index) => new BarEntry(index, x.value / 1000f))
                               .ToList();
                }
                else
                {
                    var moneyMonths = moneyStates.Where(x => x.MoneyModel.Time.Year.ToString().Equals(year))
                                      .GroupBy(x => x.MoneyModel.Time.Month)
                                      .OrderBy(x => x.Key)
                                      .Select(x => new
                    {
                        lable = dateTimeFormatInfo.GetAbbreviatedMonthName(x.Key),
                        value = x.Sum(y => y.IsPaid ? y.MoneyModel.Amount : 0)
                    }).ToList();

                    labels = moneyMonths.Select(x => x.lable).ToList();

                    barGroup = moneyMonths
                               .Select((x, index) => new BarEntry(index, x.value / 1000f))
                               .ToList();
                }

                var barDataSet = new BarDataSet(barGroup, null);
                barDataSet.SetColors(ColorTemplate.ColorfulColors.ToArray());
                barDataSet.ValueFormatter = new ValueFormatter();

                barChart.XAxis.ValueFormatter = new IndexAxisValueFormatter(labels);
                barChart.Data = new BarData(barDataSet);;
                barChart.Invalidate();
            }
        }
Esempio n. 5
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            mView           = inflater.Inflate(Resource.Layout.ChartAllTablesDialog, container, false);
            mChartAllTables = mView.FindViewById <BarChart>(Resource.Id.chartAllTablesDialog);

            dicOfDataSets = new Dictionary <string, List <BarEntry> >();

            foreach (StatsTables row in listStatsTables)
            {
                if (!listTableNames.Contains(row.table_name))
                {
                    listTableNames.Add(row.table_name);
                }
            }

            int counter = 0;


            foreach (string table in listTableNames)
            {
                List <BarEntry> barEntry = new List <BarEntry>();
                foreach (StatsTables item in listStatsTables)
                {
                    if (table == item.table_name)
                    {
                        barEntry.Add(new BarEntry(counter, item.diff_last_trans));
                        counter++;
                    }
                }
                dicOfDataSets.Add(table, barEntry);
            }

            BarData data = new BarData();

            int[] chartColors  = { Color.ParseColor("#005571"), Color.ParseColor("#227691"), Color.ParseColor("#86B1C6"), Color.ParseColor("#BCD4E0"), Color.ParseColor("#FDB813"), Color.ParseColor("#FFC54E"), Color.ParseColor("#FFD27C"), Color.ParseColor("#FFE6B9") };
            int   colorCounter = 0;

            foreach (KeyValuePair <string, List <BarEntry> > dicDataSet in dicOfDataSets)
            {
                dataSet = new BarDataSet(dicDataSet.Value, dicDataSet.Key);
                dataSet.SetColors(chartColors[colorCounter]);
                data.AddDataSet(dataSet);
                colorCounter++;
            }

            LimitLine limitLine = new LimitLine(70f);

            limitLine.LineColor = Color.DarkRed;
            limitLine.Enabled   = true;

            XAxis xAxis = mChartAllTables.XAxis;

            xAxis.SetCenterAxisLabels(false);
            xAxis.SetDrawLabels(false);
            xAxis.Position = XAxis.XAxisPosition.BottomInside;
            xAxis.SetDrawGridLines(false);

            YAxis yAxis = mChartAllTables.AxisLeft;

            yAxis.SetDrawGridLines(true);
            yAxis.AddLimitLine(limitLine);

            Legend l = mChartAllTables.Legend;

            l.VerticalAlignment   = Legend.LegendVerticalAlignment.Top;
            l.HorizontalAlignment = Legend.LegendHorizontalAlignment.Right;
            l.Orientation         = Legend.LegendOrientation.Vertical;
            l.WordWrapEnabled     = true;
            l.SetDrawInside(true);

            mChartAllTables.Data = data;
            mChartAllTables.AxisRight.SetDrawLabels(false);
            mChartAllTables.XAxis.SetDrawLabels(false);
            mChartAllTables.AnimateXY(3000, 3000);

            mChartAllTables.Description.Enabled = true;
            mChartAllTables.Description.Text    = "All tables chart";

            mChartAllTables.Invalidate();

            return(mView);
        }
Esempio n. 6
0
        private void ChartError()
        {
            mDicOfDataSets = new Dictionary <string, List <BarEntry> >();

            List <StatsTables> searchedTable = (from table in mListStatsTables
                                                where table.big_deviation.Contains("YES", StringComparison.OrdinalIgnoreCase)
                                                select table).ToList <StatsTables>();

            foreach (StatsTables row in searchedTable)
            {
                if (!mListTableNames.Contains(row.table_name))
                {
                    mListTableNames.Add(row.table_name);
                }
            }

            int counter = 0;

            foreach (string table in mListTableNames)
            {
                List <BarEntry> barEntry = new List <BarEntry>();
                foreach (StatsTables item in searchedTable)
                {
                    if (table == item.table_name)
                    {
                        barEntry.Add(new BarEntry(counter, item.diff_last_trans));
                        counter++;
                    }
                }
                mDicOfDataSets.Add(table, barEntry);
            }

            BarData data = new BarData();

            foreach (KeyValuePair <string, List <BarEntry> > dicDataSet in mDicOfDataSets)
            {
                dataSet = new BarDataSet(dicDataSet.Value, dicDataSet.Key);
                dataSet.SetColors(Color.DarkRed);
                data.AddDataSet(dataSet);
            }

            XAxis xAxis = chartError.XAxis;

            xAxis.SetCenterAxisLabels(false);
            xAxis.SetDrawLabels(false);
            xAxis.Position = XAxis.XAxisPosition.BottomInside;
            xAxis.SetDrawGridLines(false);

            chartError.Data = data;
            chartError.AxisRight.SetDrawLabels(false);
            chartError.XAxis.SetDrawLabels(false);
            chartError.AnimateXY(2000, 2000);

            chartError.Legend.Enabled = false;
            chartError.SetTouchEnabled(true);
            chartError.SetPinchZoom(false);
            chartError.DoubleTapToZoomEnabled = false;

            chartError.Description.Enabled = true;
            chartError.Description.Text    = "Tables with big deviation";

            //chartError.SetBackgroundColor(Color.WhiteSmoke);

            chartError.Invalidate();
        }
Esempio n. 7
0
        private void ChartAllTables()
        {
            mDicOfDataSets = new Dictionary <string, List <BarEntry> >();

            foreach (StatsTables row in mListStatsTables)
            {
                if (!mListTableNames.Contains(row.table_name))
                {
                    mListTableNames.Add(row.table_name);
                }
            }

            int counter = 0;


            foreach (string table in mListTableNames)
            {
                List <BarEntry> barEntry = new List <BarEntry>();
                foreach (StatsTables item in mListStatsTables)
                {
                    if (table == item.table_name)
                    {
                        barEntry.Add(new BarEntry(counter, item.diff_last_trans));
                        counter++;
                    }
                }
                mDicOfDataSets.Add(table, barEntry);
            }

            BarData data = new BarData();

            int[] chartColors = { Color.DarkRed, Color.DarkGreen };

            foreach (KeyValuePair <string, List <BarEntry> > dicDataSet in mDicOfDataSets)
            {
                dataSet = new BarDataSet(dicDataSet.Value, dicDataSet.Key);

                foreach (BarEntry item in dicDataSet.Value)
                {
                    if (item.GetY() > 70)
                    {
                        dataSet.SetColors(chartColors[0]);
                    }

                    else
                    {
                        dataSet.SetColors(chartColors[1]);
                    }
                }
                data.AddDataSet(dataSet);
            }

            LimitLine limitLine = new LimitLine(70f);

            limitLine.LineColor = Color.DarkRed;
            limitLine.Enabled   = true;

            XAxis xAxis = chartAllTables.XAxis;

            xAxis.SetDrawLabels(false);
            xAxis.Position = XAxis.XAxisPosition.BottomInside;
            xAxis.SetDrawGridLines(true);

            YAxis yAxis = chartAllTables.AxisLeft;

            yAxis.SetDrawGridLines(true);
            yAxis.AddLimitLine(limitLine);

            chartAllTables.Data = data;
            chartAllTables.AxisRight.SetDrawLabels(false);
            chartAllTables.AnimateXY(3000, 3000);

            chartAllTables.Legend.Enabled = false;
            chartAllTables.SetTouchEnabled(true);
            chartAllTables.SetPinchZoom(false);
            chartAllTables.DoubleTapToZoomEnabled = false;

            chartAllTables.Description.Enabled = true;
            chartAllTables.Description.Text    = "All tables chart";

            //chartAllTables.SetBackgroundColor(Color.WhiteSmoke);

            chartAllTables.Invalidate();
        }