コード例 #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.PieChart getPieChart(List <CE_Pesquisa03> opcoes, List <CE_Pesquisa07> respostas)
        {
            MikePhil.Charting.Charts.PieChart pieChart = new MikePhil.Charting.Charts.PieChart(Android.App.Application.Context);
            pieChart.SetMinimumWidth(500);
            pieChart.SetMinimumHeight(500);
            pieChart.SetUsePercentValues(true);
            pieChart.SetDescription("");
            //chart.SetExtraOffsets(5, 10, 5, 5);
            //chart.DragDecelerationFrictionCoef = 0.95f;

            pieChart.DrawHoleEnabled = true;
            pieChart.SetHoleColor(Android.Graphics.Color.White);
            pieChart.SetTransparentCircleColor(Android.Graphics.Color.White);
            //chart.SetTransparentCircleAlpha(110);
            //chart.HoleRadius = 58f;
            //chart.TransparentCircleRadius = 61f;
            pieChart.HoleRadius = 7f;
            pieChart.TransparentCircleRadius = 10f;

            //chart.SetDrawCenterText(false);

            //rotação
            pieChart.RotationAngle          = 0;
            pieChart.RotationEnabled        = true;
            pieChart.HighlightPerTapEnabled = true;

            //chart.max SetMaxVisibleValueCount(60);
            //chart. SetPinchZoom(true);
            //chart.back SetDrawGridBackground(false);

            //chart.XAxis.SetAxisMinValue(0f);
            //chart.XAxis.SetAxisMaxValue()

            List <Int32> allColors = new List <Int32>();
            List <Int32> colors    = new List <Int32>();

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

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

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

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

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

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

            List <MikePhil.Charting.Data.Entry> entries = new List <MikePhil.Charting.Data.Entry>();

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

            Configuracao conf = ObterConfiguracao();

            float percentualMaximo = conf.PercentualMaximoGrafico;

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

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

            // NOTE: The order of the entries when being added to the entries array determines their position around the center of
            // the chart.
            for (int i = 0; i < qt; i++)
            {
                entries.Add(new MikePhil.Charting.Data.Entry((float)respostas[i].quantidade, i));
                labels.Add(respostas[i].txresposta != null ? respostas[i].txresposta : respostas[i].vlresposta.ToString());
                CE_Pesquisa03 opcao = opcoes.FirstOrDefault(o => o.retornopesquisa.Trim() == respostas[i].vlresposta.ToString().Trim());
                colors.Add(allColors[opcao.cor]);
            }

            if (respostas.Count > 5)
            {
                if (respostas.Count == 6)
                {
                    entries.Add(new MikePhil.Charting.Data.Entry((float)respostas[5].quantidade, 5));
                    labels.Add(respostas[5].txresposta != null ? respostas[5].txresposta : respostas[5].vlresposta.ToString());
                    CE_Pesquisa03 opcao = opcoes.FirstOrDefault(o => o.retornopesquisa.Trim() == respostas[5].vlresposta.ToString().Trim());
                    colors.Add(allColors[opcao.cor]);
                }
                else
                {
                    entries.Add(new MikePhil.Charting.Data.Entry((float)respostas.Where(o => o.totalpercentual > respostas[qt - 1].totalpercentual).Sum(o => o.quantidade), qt));
                    labels.Add("Outros");
                    colors.Add(allColors[25]);
                }
            }

            MikePhil.Charting.Data.PieDataSet dataSet = new MikePhil.Charting.Data.PieDataSet(entries, "");
            dataSet.SliceSpace     = 3f;
            dataSet.SelectionShift = 5f;
            dataSet.SetColors(colors.ToArray());
            //dataSet.setSelectionShift(0f);

            MikePhil.Charting.Data.PieData data = new MikePhil.Charting.Data.PieData(labels, dataSet);
            data.SetValueFormatter(new MikePhil.Charting.Formatter.PercentFormatter());
            data.SetValueTextSize(15f);
            data.SetValueTextColor(Android.Graphics.Color.Black);
            data.SetValueTypeface(Android.Graphics.Typeface.Default);
            pieChart.Data = data;

            // undo all highlights
            pieChart.HighlightValues(null);

            pieChart.Invalidate();

            //fim data

            //pieChart.AnimateY(1400, MikePhil.Charting.Animation.Easing.EasingOption.EaseInOutQuad);

            // mChart.spin(2000, 0, 360);

            MikePhil.Charting.Components.Legend l = pieChart.Legend;
            l.Enabled = false;

            //MikePhil.Charting.Components.Legend l = pieChart.Legend;
            //l.TextSize = 15f;
            //l.Position = MikePhil.Charting.Components.Legend.LegendPosition.LeftOfChart;
            //l.XEntrySpace = 7f;
            //l.YEntrySpace = 0f;
            //l.YOffset = 0f;

            return(pieChart);
        }