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