コード例 #1
0
        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();
        }
        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;
            }
        }
コード例 #3
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();
        }
コード例 #4
0
        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();
        }
コード例 #5
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();
        }