示例#1
0
        private void AddDataSet()
        {
            List <PieEntry> yEntry = new List <PieEntry>();

            for (int i = 0; i < yData.Length; i++)
            {
                yEntry.Add(new PieEntry(yData[i], xData[i]));
            }

            PieDataSet pieDataSet = new PieDataSet(yEntry, " ");

            pieDataSet.SliceSpace    = 4;
            pieDataSet.ValueTextSize = 12;

            int[] colors = { Color.Gray, Color.Blue, Color.Red };

            pieDataSet.SetColors(colors);

            Legend legend = piechart.Legend;

            legend.Form = Legend.LegendForm.Circle;
            #pragma warning disable CS0618 // El tipo o el miembro están obsoletos
            legend.Position = Legend.LegendPosition.BelowChartCenter;
            #pragma warning restore CS0618 // El tipo o el miembro están obsoletos

            PieData pieData = new PieData(pieDataSet);

            piechart.Data = pieData;

            piechart.Invalidate();
        }
        public MainPage()
        {
            InitializeComponent();

            var entries = new List <EntryChart>();

            entries.Add(new EntryChart(0, 5));
            entries.Add(new EntryChart(1, 7));
            entries.Add(new EntryChart(2, 10));
            entries.Add(new EntryChart(3, 3));
            entries.Add(new EntryChart(4, 1));
            entries.Add(new EntryChart(5, 7));
            entries.Add(new EntryChart(6, 2));
            var dataSet = new BarDataSet(entries, "Line Chart")
            {
                DataColor = Color.Red,
                DrawValue = false,
            };

            var entries2 = new List <EntryChart>();

            entries2.Add(new EntryChart(0, 1));
            entries2.Add(new EntryChart(1, 4));
            entries2.Add(new EntryChart(2, 9));
            entries2.Add(new EntryChart(3, 6));
            entries2.Add(new EntryChart(4, 3));
            entries2.Add(new EntryChart(5, 1));
            entries2.Add(new EntryChart(6, 7));
            var dataSet2 = new BarDataSet(entries2, "Line Chart 2")
            {
                DataColor = Color.Blue,
            };

            var entries3 = new List <PieEntry>();

            entries3.Add(new PieEntry(10, "col1", Color.Accent));
            entries3.Add(new PieEntry(30, "col2", Color.AliceBlue));
            entries3.Add(new PieEntry(25, "col3", Color.AntiqueWhite));
            entries3.Add(new PieEntry(25, "col4", Color.Aqua));
            entries3.Add(new PieEntry(10, "col5", Color.Aquamarine));
            var dataSet3 = new PieDataSet(entries3, "Pie Chart 2");

            var data = new PieChartData(dataSet3, null)
            {
                ValueDisplaySize  = 13,
                ValueDisplayColor = Color.Blue,
                TextDisplaySize   = 10,
                TextDisplayColor  = Color.Green
            };

            pieChart.ChartData = data;
            //lineChart.ChartData = data;
            //lineChart.XAxisLabels = new List<string>
            //{
            //    "Col1","Col2","Col3","Col4","Col5","Col6","Col7",
            //};
            //lineChart2.ChartData = data;
        }
        protected override void OnAppearing()
        {
            base.OnAppearing();

            var FontFamily = "";

            switch (Device.RuntimePlatform)
            {
            case Device.iOS:
                FontFamily = "Pacifico-Regular";
                break;

            case Device.Android:
                FontFamily = "Fonts/Pacifico-Regular.ttf";
                break;

            default:
                break;
            }

            var entries = new List <PieEntry>();


            entries.Add(new PieEntry(10, "Col1"));
            entries.Add(new PieEntry(15, "Col2"));
            entries.Add(new PieEntry(15, "Col3"));
            entries.Add(new PieEntry(20, "Col4"));
            entries.Add(new PieEntry(35, "Col5"));
            entries.Add(new PieEntry(5, "Col6"));

            var dataSet4 = new PieDataSet(entries, "Pie DataSet")
            {
                Colors = new List <Color>()
                {
                    Color.Accent, Color.Azure, Color.Bisque, Color.Gray, Color.Green, Color.Chocolate, Color.Black
                },
                ValueLineColor  = Color.Blue,
                SliceSpace      = 5f,
                ValueFormatter  = new CustomPercentDataSetValueFormatter(),
                ValueFontFamily = FontFamily
            };
            var data4 = new PieChartData(dataSet4)
            {
            };

            var dataSet5 = new PieDataSet(entries, "Pie DataSet")
            {
            };
            var data5 = new PieChartData(dataSet5);

            pieChart.ChartData  = data4;
            pieChart2.ChartData = data5;
        }
        private void SetData(int count, int range)
        {
            IList <PieEntry> entries = new List <PieEntry>();

            // 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 < count; i++)
            {
                entries.Add(new PieEntry((float)((random.Next(range)) + range / 5),
                                         parties[i % parties.Length],
                                         start));
            }
            PieDataSet dataSet = new PieDataSet(entries, "Election Results")
            {
                IsDrawIconsEnabled = false,

                SliceSpace     = 3f,
                IconsOffset    = new SKPoint(0, 40),
                SelectionShift = 5f
            };

            // add a lot of colors

            var colors = new List <SKColor>();

            colors.AddRange(ColorTemplate.VordiplomColors);
            colors.AddRange(ColorTemplate.JoyfulColors);
            colors.AddRange(ColorTemplate.LibreryColors);
            colors.AddRange(ColorTemplate.PastelColors);
            colors.AddRange(ColorTemplate.JoyfulColors);
            colors.Add(ColorTemplate.HoleBlue);


            dataSet.Colors = colors;
            //dataSet.setSelectionShift(0f);

            PieData data = new PieData(dataSet);

            data.SetValueFormatter(new PercentFormatter());
            data.SetValueTextSize(11f);
            data.SetValueTextColor(SKColors.White);
            data.SetValueTypeface(FontManager.Default);
            Chart.Data = data;

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

            Chart.InvalidateSurface();
        }
示例#5
0
        private PieChartViewModel GetPieChart2()
        {
            PieDataSet dataset = new PieDataSet()
            {
                data                 = new int[] { 300, 150, 40 },
                backgroundColor      = new string[] { "#FF6384", "#36A2EB", "#FFCE56" },
                hoverBackgroundColor = new string[] { "#FF6384", "#36A2EB", "#FFCE56" }
            };

            PieChartViewModel vm = new PieChartViewModel()
            {
                labels   = new string[] { "D", "E", "F" },
                datasets = new PieDataSet[] { dataset }
            };

            return(vm);
        }
示例#6
0
        protected override void OnElementChanged(ElementChangedEventArgs <Core.Common.PieChart> e)
        {
            base.OnElementChanged(e);

            if (Control == null)
            {
                var chart   = new PieChart(Context);
                var entries = new List <PieEntry>();
                entries.Add(new PieEntry(90));
                entries.Add(new PieEntry(10));
                var dataSet = new PieDataSet(entries, "Label");
                var pieData = new PieData(dataSet);
                chart.Data = pieData;
                chart.Invalidate();
                SetNativeControl(chart);
            }
        }
        private void InitializeChart()
        {
            if (supportChart != null && supportChart.ChartData != null && chartOriginal != null)
            {
                var data = supportChart.ChartData.IF_GetDataSet();

                var        entryOriginal = data.IF_GetEntry().Select(item => new MikePhil.Charting.Data.PieEntry(item.GetPercent(), item.GetText()));
                PieDataSet lineDataSet   = new PieDataSet(entryOriginal.ToArray(), data.IF_GetTitle());
                lineDataSet.SetColors(data.IF_GetEntry().Select(item => item.GetColorFill().ToAndroid().ToArgb()).ToArray());
                PieData lineData = new PieData(lineDataSet);
                lineData.SetValueFormatter(new PercentFormatter());
                lineData.SetValueTextSize(supportChart.ChartData.ValueDisplaySize);
                lineData.SetValueTextColor(supportChart.ChartData.ValueDisplayColor.ToAndroid());
                chartOriginal.SetEntryLabelColor(supportChart.ChartData.TextDisplayColor.ToAndroid());
                chartOriginal.SetEntryLabelTextSize(supportChart.ChartData.TextDisplaySize);
                chartOriginal.Data = lineData;
            }
        }
        protected override void OnInitializeChartData()
        {
            base.OnInitializeChartData();
            if (OriginalChartView != null && SupportChartView != null && SupportChartView.ChartData != null)
            {
                var dataSupport   = SupportChartView.ChartData;
                var dataSetSource = dataSupport.DataSets.FirstOrDefault();

                if (dataSetSource != null)
                {
                    var        entryOriginal = dataSetSource.IF_GetValues().Select(item => new PieEntry(item.GetPercent(), item.GetText()));
                    PieDataSet dataSet       = new PieDataSet(entryOriginal.ToArray(), dataSetSource.IF_GetLabel());
                    OnIntializeDataSet(dataSetSource, dataSet);
                    var data = new PieData(dataSet);
                    OriginalChartView.Data = data;
                }
                OriginalChartView.Invalidate();
            }
        }
示例#9
0
        private void AddDataSet()
        {
            List <PieEntry> yEntry = new List <PieEntry>();
            List <string>   xEntry = new List <string>();

            for (int i = 0; i < yData.Length; i++)
            {
                yEntry.Add(new PieEntry(yData[i], xData[i]));
            }
            for (int i = 0; i < xData.Length; i++)
            {
                xEntry.Add(xData[i]);
            }

            PieDataSet pieDataSet = new PieDataSet(yEntry, "Employee Sales");

            pieDataSet.SliceSpace    = 2;
            pieDataSet.ValueTextSize = 12;


            int[] colors = { Color.Blue.B *255, Color.Red.R *255, Color.Green.G *255 };

            pieDataSet.SetColors();
        }
示例#10
0
        private void SetChartData()
        {
            var chart = FindViewById <PieChart>(Resource.Id.chart);

            chart.RotationAngle          = 0;
            chart.RotationEnabled        = true;
            chart.HighlightPerTapEnabled = false;
            chart.SetUsePercentValues(true);
            chart.Description.Enabled = false;
            chart.SetExtraOffsets(5, 10, 5, 5);

            chart.DrawHoleEnabled = true;
            chart.SetHoleColor(Color.Transparent);
            chart.HoleRadius = 7f;

            chart.AnimateY(1400, Easing.EasingOption.EaseInOutQuad);

            var entries = new List <PieEntry>();
            var values  = ViewModel.StatisticItems.Select(x => x.Value).ToList();
            var labels  = ViewModel.StatisticItems.Select(x => x.Label).ToList();

            for (int i = 0; i < values.Count; i++)
            {
                entries.Add(new PieEntry((float)values[i], labels[i]));
            }

            var dataSet = new PieDataSet(entries, "")
            {
                SliceSpace = 1f
            };

            dataSet.AddColor(Resources.GetColor(Resource.Color.color_spreading1, Theme));
            dataSet.AddColor(Resources.GetColor(Resource.Color.color_spreading2, Theme));
            dataSet.AddColor(Resources.GetColor(Resource.Color.color_spreading3, Theme));
            dataSet.AddColor(Resources.GetColor(Resource.Color.color_spreading4, Theme));
            dataSet.AddColor(Resources.GetColor(Resource.Color.color_spreading5, Theme));
            dataSet.AddColor(Resources.GetColor(Resource.Color.color_spreading6, Theme));
            dataSet.AddColor(Resources.GetColor(Resource.Color.color_spreading7, Theme));

            var data = new PieData(dataSet);

            data.SetValueFormatter(new PercentFormatter());
            data.SetValueTextSize(11f);
            data.SetValueTextColor(Color.White);

            chart.SetDrawEntryLabels(false);
            chart.Data = data;

            var legend = chart.Legend;

            legend.TextSize    = 12f;
            legend.Orientation = Legend.LegendOrientation.Vertical;
            legend.SetDrawInside(false);
            legend.VerticalAlignment   = Legend.LegendVerticalAlignment.Top;
            legend.HorizontalAlignment = Legend.LegendHorizontalAlignment.Left;
            legend.XEntrySpace         = 7f;
            legend.YEntrySpace         = 0;
            legend.YOffset             = 0f;

            chart.HighlightValues(null);
            chart.Invalidate();
        }
        void SetData(int count, float range)
        {
            float mult = range;

            var yVals1 = new List<Entry>();

            // IMPORTANT: In a PieChart, no values (Entry) should have the same
            // xIndex (even if from different DataSets), since no values can be
            // drawn above each other.
            for (int i = 0; i < count + 1; i++) {
                yVals1.Add(new Entry((float) (new Random().Next() * mult) + mult / 5, i));
            }

            var xVals = new List<String>();

            for (int i = 0; i < count + 1; i++)
                xVals.Add(mParties[i % mParties.Length]);

            PieDataSet dataSet = new PieDataSet(yVals1, "Election Results");
            dataSet.SliceSpace = 2f;
            dataSet.SelectionShift = 5f;

            var colors = new List<Java.Lang.Integer>();

            foreach (Java.Lang.Integer c in ColorTemplate.VordiplomColors)
                colors.Add(c);

            foreach (Java.Lang.Integer c in ColorTemplate.JoyfulColors)
                colors.Add(c);

            foreach (Java.Lang.Integer c in ColorTemplate.ColorfulColors)
                colors.Add(c);

            foreach (Java.Lang.Integer c in ColorTemplate.LibertyColors)
                colors.Add(c);

            foreach (Java.Lang.Integer c in ColorTemplate.PastelColors)
                colors.Add(c);

            colors.Add((Java.Lang.Integer)ColorTemplate.HoloBlue);

            dataSet.Colors = colors;
            //dataSet.setSelectionShift(0f);

            PieData data = new PieData(xVals, dataSet);
            data.SetValueFormatter(new PercentFormatter());
            data.SetValueTextSize(11f);
            data.SetValueTextColor(Color.White);
            data.SetValueTypeface(tf);
            mChart.Data = data;

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

            mChart.Invalidate();
        }
示例#12
0
        private void ChartsPage_Load(object sender, EventArgs e)
        {
            LineDataSet      lineDataSet1      = new LineDataSet();
            LineDataSet      lineDataSet2      = new LineDataSet();
            BarDataSet       barDataSet1       = new BarDataSet();
            RadarDataSet     radarDataSet1     = new RadarDataSet();
            PolarAreaDataSet polarAreaDataSet1 = new PolarAreaDataSet();
            DoughnutDataSet  doughnutDataSet1  = new DoughnutDataSet();
            PieDataSet       pieDataSet1       = new PieDataSet();

            lineDataSet1.BackgroundColor      = Color.FromArgb(70, 255, 189, 0);
            lineDataSet1.BorderColor          = Color.FromArgb(255, 46, 0);
            lineDataSet1.Data                 = new object[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
            lineDataSet1.PointBorderColor     = new[] { Color.FromArgb(0, 255, 0) };
            lineDataSet1.PointBackgroundColor = new[] { Color.FromArgb(0, 255, 0) };
            lineDataSet1.Fill                 = true;
            lineDataSet1.Label                = "Data Set";
            lineDataSet2.BorderColor          = Color.FromArgb(0, 86, 255);
            lineDataSet2.Data                 = new object[] { 1, 2, 4, 8, 16, 32, 64, 32, 16, 8, 4, 2 };
            lineDataSet2.Label                = "Data Set 2";
            lineDataSet2.PointStyle           = new[] { PointStyle.RectRounded };
            lineDataSet2.SteppedLine          = SteppedLine.After;
            chartJS1.DataSets.Add(lineDataSet1);
            chartJS1.DataSets.Add(lineDataSet2);

            barDataSet1.BackgroundColor = new[]
            {
                Color.FromArgb(49, 255, 0, 0),
                Color.FromArgb(58, 102, 255, 0),
                Color.FromArgb(52, 0, 183, 255),
                Color.FromArgb(53, 247, 0, 255),
                Color.FromArgb(52, 191, 123, 63),
                Color.FromArgb(53, 191, 63, 86),
                Color.FromArgb(104, 255, 0, 118),
                Color.FromArgb(237, 130, 237),
                Color.FromArgb(88, 64, 224, 208),
                Color.FromArgb(84, 255, 98, 70),
                Color.FromArgb(60, 41, 69, 70),
                Color.FromArgb(98, 0, 0, 128)
            };
            barDataSet1.BorderColor          = null;
            barDataSet1.Data                 = new object[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
            barDataSet1.HoverBackgroundColor = null;
            barDataSet1.Label                = "Data Set";
            chartJS2.DataSets.Add(barDataSet1);

            radarDataSet1.BackgroundColor = Color.FromArgb(72, 79, 191, 63);
            radarDataSet1.Data            = new object[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
            radarDataSet1.Label           = "Data Set";
            chartJS4.DataSets.Add(radarDataSet1);

            polarAreaDataSet1.BackgroundColor = new[]
            {
                Color.FromArgb(49, 255, 0, 0),
                Color.FromArgb(58, 102, 255, 0),
                Color.FromArgb(52, 0, 183, 255),
                Color.FromArgb(53, 247, 0, 255),
                Color.FromArgb(52, 191, 123, 63),
                Color.FromArgb(53, 191, 63, 86),
                Color.FromArgb(104, 255, 0, 118),
                Color.FromArgb(237, 130, 237),
                Color.FromArgb(88, 64, 224, 208),
                Color.FromArgb(84, 255, 98, 70),
                Color.FromArgb(60, 41, 69, 70),
                Color.FromArgb(98, 0, 0, 128)
            };
            polarAreaDataSet1.BorderColor          = null;
            polarAreaDataSet1.Data                 = new object[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0 };
            polarAreaDataSet1.HoverBackgroundColor = null;
            polarAreaDataSet1.Label                = "Data Set";
            chartJS6.DataSets.Add(polarAreaDataSet1);

            doughnutDataSet1.BackgroundColor = new[]
            {
                Color.FromArgb(49, 255, 0, 0),
                Color.FromArgb(58, 102, 255, 0),
                Color.FromArgb(52, 0, 183, 255),
                Color.FromArgb(53, 247, 0, 255),
                Color.FromArgb(52, 191, 123, 63),
                Color.FromArgb(53, 191, 63, 86),
                Color.FromArgb(104, 255, 0, 118),
                Color.FromArgb(237, 130, 237),
                Color.FromArgb(88, 64, 224, 208),
                Color.FromArgb(84, 255, 98, 70),
                Color.FromArgb(60, 41, 69, 70),
                Color.FromArgb(98, 0, 0, 128)
            };
            doughnutDataSet1.BorderColor          = null;
            doughnutDataSet1.Data                 = new object[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0 };
            doughnutDataSet1.HoverBackgroundColor = null;
            doughnutDataSet1.Label                = "Data Set";
            chartJS5.DataSets.Add(doughnutDataSet1);

            pieDataSet1.BackgroundColor = new[]
            {
                Color.FromArgb(49, 255, 0, 0),
                Color.FromArgb(58, 102, 255, 0),
                Color.FromArgb(52, 0, 183, 255),
                Color.FromArgb(53, 247, 0, 255),
                Color.FromArgb(52, 191, 123, 63),
                Color.FromArgb(53, 191, 63, 86),
                Color.FromArgb(104, 255, 0, 118),
                Color.FromArgb(237, 130, 237),
                Color.FromArgb(88, 64, 224, 208),
                Color.FromArgb(84, 255, 98, 70),
                Color.FromArgb(60, 41, 69, 70),
                Color.FromArgb(98, 0, 0, 128)
            };
            pieDataSet1.BorderColor          = null;
            pieDataSet1.Data                 = new object[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
            pieDataSet1.HoverBackgroundColor = null;
            pieDataSet1.Label                = "Data Set";
            chartJS3.DataSets.Add(pieDataSet1);

            Randomize();
        }
示例#13
0
        private void MyPieChart()
        {
            sumOfLowOccupancy = (from table in mListStatsColumns
                                 where table.LOW_OCCUPANCY.Contains("YES", StringComparison.OrdinalIgnoreCase)
                                 select table).Count();


            sumOfHighOccupancy = (from table in mListStatsColumns
                                  where table.LOW_OCCUPANCY.Contains("NO", StringComparison.OrdinalIgnoreCase)
                                  select table).Count();

            resoultHighOccupancy = (sumOfHighOccupancy / sumOfLowOccupancy) * 100;

            resoultLowOccupncy = (sumOfLowOccupancy / sumOfHighOccupancy) * 100;

            mListOfEntry = new List <PieEntry>();

            mListOfEntry.Add(new PieEntry(resoultHighOccupancy, "High occupancy"));
            mListOfEntry.Add(new PieEntry(resoultLowOccupncy, "Low occupancy"));

            dataSet = new PieDataSet(mListOfEntry, "");

            dataSet.SliceSpace     = 3;
            dataSet.SelectionShift = 2;
            dataSet.SetColor(Color.DarkGreen, 200);
            dataSet.AddColor(Color.DarkRed);

            PieData data = new PieData(dataSet);

            data.SetValueFormatter(new PercentFormatter());
            data.SetValueTextSize(11f);
            data.SetValueTextColor(Color.Black);

            mPieChart.Data = data;

            mPieChart.HighlightValues(null);

            mPieChart.SetUsePercentValues(true);
            mPieChart.Description.Enabled = false;
            mPieChart.SetExtraOffsets(5, 10, 5, 5);

            mPieChart.DrawHoleEnabled = true;
            mPieChart.SetHoleColor(Color.White);
            mPieChart.HoleRadius = 7;
            mPieChart.SetTransparentCircleAlpha(10);

            mPieChart.RotationAngle   = 0;
            mPieChart.RotationEnabled = true;

            mPieChart.HighlightPerTapEnabled = true;

            mPieChart.AnimateY(2000, Easing.EasingOption.EaseInOutQuad);

            Legend legend = mPieChart.Legend;

            legend.Position    = Legend.LegendPosition.RightOfChart;
            legend.XEntrySpace = 7;
            legend.YEntrySpace = 5;

            mPieChart.Invalidate();
        }
        private void OnIntializeDataSet(Widget.Charts.Models.PieChart.IPieDataSet source, PieDataSet original)
        {
            /*
             * Properies could not net
             * IF_GetUsingSliceColorAsValueLineColor
             */
            Export.OnSettingsBaseDataSet(source, original);

            if (source.IF_GetSliceSpace().HasValue)
            {
                original.SliceSpace = (source.IF_GetSliceSpace().Value);
            }

            if (source.IF_GetAutomaticallyDisableSliceSpacing().HasValue)
            {
                original.SetAutomaticallyDisableSliceSpacing(source.IF_GetAutomaticallyDisableSliceSpacing().Value);
            }

            if (source.IF_GetShift().HasValue)
            {
                original.SelectionShift = (source.IF_GetShift().Value);
            }

            if (source.IF_GetValueLineColor().HasValue)
            {
                original.ValueLineColor = (source.IF_GetValueLineColor().Value.ToAndroid());
            }

            if (source.IF_GetValueLineWidth().HasValue)
            {
                original.ValueLineWidth = (source.IF_GetValueLineWidth().Value);
            }

            if (source.IF_GetValueLinePart1OffsetPercentage().HasValue)
            {
                original.ValueLinePart1OffsetPercentage = (source.IF_GetValueLinePart1OffsetPercentage().Value);
            }

            if (source.IF_GetValueLinePart1Length().HasValue)
            {
                original.ValueLinePart1Length = (source.IF_GetValueLinePart1Length().Value);
            }

            if (source.IF_GetValueLinePart2Length().HasValue)
            {
                original.ValueLinePart2Length = (source.IF_GetValueLinePart2Length().Value);
            }

            if (source.IF_GetValueLineVariableLength().HasValue)
            {
                original.SetValueLineVariableLength(source.IF_GetValueLineVariableLength().Value);
            }

            if (source.IF_GetXValuePosition().HasValue)
            {
                original.XValuePosition = source.IF_GetXValuePosition().Value == Widget.Charts.Models.PieChart.ValuePosition.INSIDE_SLICE ? PieDataSet.ValuePosition.InsideSlice : PieDataSet.ValuePosition.OutsideSlice;
            }

            if (source.IF_GetYValuePosition().HasValue)
            {
                original.YValuePosition = source.IF_GetYValuePosition().Value == Widget.Charts.Models.PieChart.ValuePosition.INSIDE_SLICE ? PieDataSet.ValuePosition.InsideSlice : PieDataSet.ValuePosition.OutsideSlice;
            }
        }
示例#15
0
        private View CreateUserListStatusView(IReadOnlyList <AniListStatusDistribution> statusDistribution)
        {
            var detailView      = LayoutInflater.Inflate(Resource.Layout.View_AniListObjectDetail, null);
            var detailContainer = detailView.FindViewById <LinearLayout>(Resource.Id.AniListObjectDetail_InnerContainer);

            detailView.FindViewById <TextView>(Resource.Id.AniListObjectDetail_Name).Text = "User Lists";
            detailContainer.Orientation = Orientation.Horizontal;

            var chartHeight  = Resources.GetDimensionPixelSize(Resource.Dimension.Details_ChartHeight);
            var legendMargin = Resources.GetDimensionPixelSize(Resource.Dimension.Details_MarginSmall);

            var chartContainer = new LinearLayout(this)
            {
                LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, chartHeight, 1)
            };

            var legendContainer = new LinearLayout(this)
            {
                LayoutParameters =
                    new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, chartHeight, 1)
                {
                    RightMargin = legendMargin,
                    LeftMargin  = legendMargin
                },
                Orientation = Orientation.Vertical
            };

            var typedColorArray = Resources.ObtainTypedArray(Resource.Array.Chart_Colors);
            var colorList       = new List <int>();

            for (var i = 0; i < typedColorArray.Length(); i++)
            {
                colorList.Add(typedColorArray.GetColor(i, 0));
            }

            var statusChart = new PieChart(this)
            {
                LayoutParameters =
                    new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent)
            };
            var slices = statusDistribution.Select(x => new PieEntry(x.Amount, x.Status.DisplayValue)
            {
                Data = x.Status.DisplayValue
            }).ToList();
            var dataSet = new PieDataSet(slices, "Status")
            {
                SliceSpace = 1,
            };

            dataSet.SetDrawValues(false);
            dataSet.SetColors(colorList.ToArray(), 255);
            var data = new PieData(dataSet);

            statusChart.TransparentCircleRadius = 0;
            statusChart.HoleRadius = 0;
            statusChart.Data       = data;
            statusChart.SetDrawEntryLabels(false);
            statusChart.Description.Enabled = false;
            statusChart.Legend.Enabled      = false;
            statusChart.RotationEnabled     = false;

            chartContainer.AddView(statusChart);

            for (var i = 0; i < statusDistribution.Count; i++)
            {
                var cell   = LayoutInflater.Inflate(Resource.Layout.View_ChartLegendCell, legendContainer, false);
                var status = statusDistribution[i];
                cell.SetBackgroundColor(new Color(colorList[i % 10]));
                cell.FindViewById <TextView>(Resource.Id.ChartLegendCell_Count).Text = status.Amount.ToTruncatedString();
                cell.FindViewById <TextView>(Resource.Id.ChartLegendCell_Text).Text  = status.Status.DisplayValue;
                cell.Tag = status.Status.DisplayValue;
                legendContainer.AddView(cell);
            }

            detailContainer.AddView(chartContainer);
            detailContainer.AddView(legendContainer);

            return(detailView);
        }