コード例 #1
0
        protected async override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_stats);
            this.Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
            this.Window.ClearFlags(WindowManagerFlags.TranslucentStatus);
            this.Window.SetStatusBarColor(Android.Graphics.Color.ParseColor("#204060"));
            var toolbar = FindViewById <Toolbar>(Resource.Id.toolbarstats);

            SetSupportActionBar(toolbar);
            toolbar.SetNavigationOnClickListener(this);
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            SupportActionBar.SetDisplayShowHomeEnabled(true);
            toolbar.NavigationIcon.SetColorFilter(Android.Graphics.Color.ParseColor("#04040C"), PorterDuff.Mode.SrcAtop);
            statstype           = FindViewById <TextView>(Resource.Id.statstype);
            statsdata           = FindViewById <TextView>(Resource.Id.statsdata);
            generatePDF         = FindViewById <Button>(Resource.Id.generatePDF);
            showbarchart        = FindViewById <ImageView>(Resource.Id.showbarchart);
            showbarchart.Click += Showbarchart_Click;
            showpiechart        = FindViewById <ImageView>(Resource.Id.showpiechart);
            showpiechart.Click += Showpiechart_Click;
            analysistype        = FindViewById <TextView>(Resource.Id.analysistype);
            analysistype.Text   = "Category-wise Expenses";
            //chartview = FindViewById<ChartView>(Resource.Id.chartview);
            monthcontainer         = FindViewById <RelativeLayout>(Resource.Id.monthcontainer);
            progressBarStats       = FindViewById <ProgressBar>(Resource.Id.progressBarStats);
            rootView               = FindViewById <CoordinatorLayout>(Resource.Id.rootView);
            monthspinner           = FindViewById <Spinner>(Resource.Id.monthspinner);
            CurrentUserUid         = Intent.GetStringExtra("CurrentUserUid");
            SelectedYear           = Intent.GetStringExtra("SelectedYear");
            SelectedMonth          = Intent.GetStringExtra("SelectedMonth");
            CurrentUserDisplayName = Intent.GetStringExtra("CurrentUserDisplayName");
            prefs = PreferenceManager.GetDefaultSharedPreferences(this);
            //statstype.Text = "Total expense for the year"+"("+ SelectedYear+")";
            piechartStats = FindViewById <MikePhil.Charting.Charts.PieChart>(Resource.Id.piechartStats);
            piechartStats.SetNoDataText("");

            barchartStats = FindViewById <MikePhil.Charting.Charts.BarChart>(Resource.Id.barchartStats);
            barchartStats.SetNoDataText("");
            barchartStats.Description.Enabled = false;
            barchartStats.AxisRight.SetDrawLabels(false);
            database          = AppDataHelper.GetDatabase();
            IsPieChartSeleted = true;
            SetupMonthSpinner();
            //FetchExpensesTableForMonth();

            // await Common.WriteFileToStorageAsync(this, "PlayfairDisplay-Regular.ttf");
            await Common.WriteFileToStorageAsync(this, "nunitosans.ttf");

            Dexter.WithActivity(this).WithPermission(Android.Manifest.Permission.WriteExternalStorage).WithListener(this).Check();
            generatePDF.Click -= GeneratePDF_Click;
            generatePDF.Click += GeneratePDF_Click;
        }
コード例 #2
0
        public MikePhil.Charting.Charts.BarChart getBarChart(List <CE_Pesquisa07> respostas, List <CE_Pesquisa06> ondas)
        {
            MikePhil.Charting.Charts.BarChart barChart = new MikePhil.Charting.Charts.BarChart(Android.App.Application.Context);

            try
            {
                List <Int32> colors = new List <Int32>();

                foreach (int c in MikePhil.Charting.Util.ColorTemplate.VordiplomColors)
                {
                    colors.Add(c);
                }

                foreach (int c in MikePhil.Charting.Util.ColorTemplate.JoyfulColors)
                {
                    colors.Add(c);
                }

                foreach (int c in MikePhil.Charting.Util.ColorTemplate.ColorfulColors)
                {
                    colors.Add(c);
                }

                foreach (int c in MikePhil.Charting.Util.ColorTemplate.LibertyColors)
                {
                    colors.Add(c);
                }

                foreach (int c in MikePhil.Charting.Util.ColorTemplate.PastelColors)
                {
                    colors.Add(c);
                }

                colors.Add(MikePhil.Charting.Util.ColorTemplate.HoloBlue);

                List <MikePhil.Charting.Interfaces.Datasets.IBarDataSet> datasets = new List <MikePhil.Charting.Interfaces.Datasets.IBarDataSet>();

                List <string> labels = new List <string>();

                Configuracao conf = ObterConfiguracao();

                float percentualMaximo = conf.PercentualMaximoGrafico;

                respostas = respostas.OrderBy(o => o.txresposta).ToList();

                int qt = respostas.Count > 3 ? 3 : respostas.Count;//respostas.Count > 5 ? respostas.IndexOf(respostas.FirstOrDefault(o => o.totalpercentual > (decimal)percentualMaximo)) + 1 : respostas.Count;

                for (int i = 0; i < qt; i++)
                {
                    labels.Add(respostas[i].txresposta != null ? respostas[i].txresposta : respostas[i].vlresposta.ToString());
                }

                /*if(respostas.Count > 5)
                 * {
                 *  if (respostas.Count == 6)
                 *      labels.Add(respostas[5].txresposta != null ? respostas[5].txresposta : respostas[5].vlresposta.ToString());
                 *  else
                 *      labels.Add("Outros");
                 * }*/

                for (int j = 1; j <= ondas.Count; j++)
                {
                    List <MikePhil.Charting.Data.BarEntry> barEntries = new List <MikePhil.Charting.Data.BarEntry>();

                    for (int i = 0; i < qt; i++)
                    {
                        float[] vals = new float[] { float.Parse(GetPropValue(respostas[i], "percentual" + j).ToString()) };
                        barEntries.Add(new MikePhil.Charting.Data.BarEntry(vals, i));
                    }

                    /*if (respostas.Count > 5)
                     * {
                     *  if (respostas.Count == 6)
                     *  {
                     *      barEntries.Add(new MikePhil.Charting.Data.BarEntry((float)GetPropValue(respostas[5], "percentual" + j), 5));
                     *  }
                     *  else
                     *  {
                     *      List<CE_Pesquisa07> outros = respostas.Where(o => o.totalpercentual > respostas[qt - 1].totalpercentual).ToList();
                     *
                     *      float valor = 0;
                     *
                     *      foreach (var item in outros)
                     *      {
                     *          valor += (float)GetPropValue(item, "percentual" + j);
                     *      }
                     *
                     *      barEntries.Add(new MikePhil.Charting.Data.BarEntry(valor, qt));
                     *  }
                     * }*/

                    MikePhil.Charting.Data.BarDataSet barDataSet = new MikePhil.Charting.Data.BarDataSet(barEntries, null);
                    barDataSet.SetColors(colors.ToArray());

                    datasets.Add(barDataSet);
                }

                MikePhil.Charting.Data.BarData barData = new MikePhil.Charting.Data.BarData(labels, datasets);
                barData.SetValueTextSize(15f);
                barChart.Data = barData;

                barChart.SetDescription("");
                barChart.Legend.Enabled = false;
                barChart.HighlightValues(null);
                barChart.Invalidate();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(barChart);
        }