Beispiel #1
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);
        }
Beispiel #2
0
        public MikePhil.Charting.Charts.HorizontalBarChart getHorizontalBarChart(List <CE_Pesquisa07> respostas)
        {
            MikePhil.Charting.Charts.HorizontalBarChart barChart = new MikePhil.Charting.Charts.HorizontalBarChart(Android.App.Application.Context);

            List <MikePhil.Charting.Data.BarEntry> barEntries = new List <MikePhil.Charting.Data.BarEntry>();

            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++)
            {
                barEntries.Add(new MikePhil.Charting.Data.BarEntry((float)respostas[i].percentual, i, respostas[i].txresposta != null ? respostas[i].txresposta : respostas[i].vlresposta.ToString()));
                labels.Add(respostas[i].txresposta != null ? respostas[i].txresposta : respostas[i].vlresposta.ToString());
            }

            if (respostas.Count > 5)
            {
                if (respostas.Count == 6)
                {
                    barEntries.Add(new MikePhil.Charting.Data.BarEntry((float)respostas[5].percentual, 5));
                    labels.Add(respostas[5].txresposta != null ? respostas[5].txresposta : respostas[5].vlresposta.ToString());
                }
                else
                {
                    barEntries.Add(new MikePhil.Charting.Data.BarEntry((float)respostas.Where(o => o.totalpercentual > respostas[qt - 1].totalpercentual).Sum(o => o.percentual), qt));
                    labels.Add("Outros");
                }
            }

            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);

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

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

            barChart.SetDescription("");
            //barChart.AnimateY(1400, MikePhil.Charting.Animation.Easing.EasingOption.EaseInOutQuad);
            barChart.HighlightValues(null);
            barChart.Invalidate();

            return(barChart);
        }