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 ChartDataEntry(item.GetPercent(), item.GetPercent())); PieChartDataSet lineDataSet = new PieChartDataSet(entryOriginal.ToArray(), data.IF_GetTitle()); lineDataSet.SetColors(data.IF_GetEntry().Select(item => item.GetColorFill().ToUIColor()).ToArray(), 1f); PieChartData lineData = new PieChartData(new PieChartDataSet[] { lineDataSet }); //lineData.SetValueTextSize(supportChart.ChartData.ValueDisplaySize); lineData.SetValueTextColor(supportChart.ChartData.ValueDisplayColor.ToUIColor()); chartOriginal.EntryLabelColor = (supportChart.ChartData.TextDisplayColor.ToUIColor()); //chartOriginal.SetEntryLabelTextSize(supportChart.ChartData.TextDisplaySize); //chartOriginal.XAxis.ValueFormatter = new ChartIndexAxisValueFormatter(data.IF_GetEntry().Select(item => item.GetText()).ToArray()); 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 PieChartDataEntry(item.GetPercent(), item.GetText())); PieChartDataSet dataSet = new PieChartDataSet(entryOriginal.ToArray(), dataSetSource.IF_GetLabel()); OnIntializeDataSet(dataSetSource, dataSet); PieChartData chartData = new PieChartData(new PieChartDataSet[] { dataSet }); OriginalChartView.Data = chartData; } OriginalChartView.ReloadInputViews(); OriginalChartView.SetNeedsDisplay(); } }
public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath) { var resultCell = collectionView.DequeueReusableCell(ResultViewController.resultCellId, indexPath) as ResultCollectionViewCell; resultCell.BackgroundColor = UIColor.White; var reportDataSet = this.reportsDatasets[indexPath.Row]; if (ReportType.Overall.Equals(reports[indexPath.Row])) { resultCell.sectionLabel.Text = reports[indexPath.Row].ToString(); if (reportDataSet.totalVotes > 0) { var dataEntries = new List <PieChartDataEntry>(); for (int i = 0; i < reportDataSet.dataSets[0].Count; i++) { if (Convert.ToInt32(reportDataSet.dataSets[0][i]) > 0) { dataEntries.Add(new PieChartDataEntry(reportDataSet.dataSets[0][i], reportDataSet.labels[i])); } } var dataSet = new PieChartDataSet(dataEntries.ToArray(), ""); dataSet.ValueFormatter = new ChartDefaultValueFormatter(new NSNumberFormatter() { MinimumFractionDigits = 0 }); dataSet.SliceSpace = 2; //dataSet.Colors = ChartColorTemplates.Joyful; dataSet.Colors = this.chartColors.ToArray(); dataSet.ValueTextColor = UIColor.FromRGB(90, 89, 89); dataSet.ValueLineColor = UIColor.FromRGB(90, 89, 89); dataSet.EntryLabelColor = UIColor.FromRGB(90, 89, 89); dataSet.XValuePosition = PieChartValuePosition.OutsideSlice; dataSet.YValuePosition = PieChartValuePosition.OutsideSlice; resultCell.pieChartView.Data = new PieChartData(new PieChartDataSet[] { dataSet }); } resultCell.pieChartView.AnimateWithXAxisDuration(1.4, ChartEasingOption.EaseOutBack); resultCell.pieChartView.ChartDescription.Text = ""; var colorAttributes = new UIStringAttributes { ForegroundColor = UIColor.FromRGB(90, 89, 89) }; resultCell.pieChartView.CenterAttributedText = new NSAttributedString(string.Format("Total {0} votes", reportDataSet.totalVotes, colorAttributes)); resultCell.pieChartView.Legend.Enabled = false; resultCell.pieChartView.NoDataText = "No results to show"; resultCell.AddSubview(resultCell.pieChartView); resultCell.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|[v0]|", new NSLayoutFormatOptions(), "v0", resultCell.pieChartView)); resultCell.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:|[v0(24)][v1]|", new NSLayoutFormatOptions(), "v0", resultCell.sectionLabel, "v1", resultCell.pieChartView)); } else { resultCell.sectionLabel.Text = "By " + reports[indexPath.Row].ToString(); resultCell.barChartView.Legend.Enabled = true; resultCell.barChartView.Legend.HorizontalAlignment = ChartLegendHorizontalAlignment.Right; resultCell.barChartView.Legend.VerticalAlignment = ChartLegendVerticalAlignment.Top; resultCell.barChartView.Legend.Orientation = ChartLegendOrientation.Vertical; resultCell.barChartView.Legend.DrawInside = true; resultCell.barChartView.Legend.YOffset = 10.0f; resultCell.barChartView.Legend.XOffset = 10.0f; resultCell.barChartView.Legend.YEntrySpace = 0.0f; resultCell.barChartView.Legend.TextColor = UIColor.FromRGB(90, 89, 89); resultCell.barChartView.XAxis.DrawGridLinesEnabled = true; resultCell.barChartView.XAxis.LabelPosition = XAxisLabelPosition.Bottom; resultCell.barChartView.XAxis.CenterAxisLabelsEnabled = true; resultCell.barChartView.XAxis.ValueFormatter = new ChartIndexAxisValueFormatter(TranslateReportGroups(reportDataSet.groups.ToArray())); resultCell.barChartView.XAxis.Granularity = 1; resultCell.barChartView.XAxis.LabelTextColor = UIColor.FromRGB(90, 89, 89); resultCell.barChartView.XAxis.GridColor = UIColor.FromRGB(90, 89, 89); resultCell.barChartView.XAxis.AxisLineColor = UIColor.FromRGB(90, 89, 89); resultCell.barChartView.LeftAxis.SpaceTop = 0.35f; resultCell.barChartView.LeftAxis.AxisMinimum = 0; resultCell.barChartView.LeftAxis.DrawGridLinesEnabled = false; resultCell.barChartView.LeftAxis.Granularity = 1; resultCell.barChartView.LeftAxis.ValueFormatter = new ChartDefaultAxisValueFormatter(new NSNumberFormatter() { MinimumFractionDigits = 0 }); resultCell.barChartView.LeftAxis.LabelTextColor = UIColor.FromRGB(90, 89, 89); resultCell.barChartView.LeftAxis.GridColor = UIColor.FromRGB(90, 89, 89); resultCell.barChartView.LeftAxis.AxisLineColor = UIColor.FromRGB(90, 89, 89); resultCell.barChartView.LeftAxis.ZeroLineColor = UIColor.FromRGB(90, 89, 89); resultCell.barChartView.RightAxis.Enabled = false; if (reportDataSet.totalVotes > 0) { var groupCount = reportDataSet.groups.Count; var optionsCount = reportDataSet.labels.Count; var dataEntriesList = new List <List <BarChartDataEntry> >(); for (int i = 0; i < optionsCount; i++) { var dataEntries = new List <BarChartDataEntry>(); for (int j = 0; j < groupCount; j++) { if (Convert.ToInt32(reportDataSet.dataSets[i][j]) > 0) { dataEntries.Add(new BarChartDataEntry(i, reportDataSet.dataSets[i][j])); } } dataEntriesList.Add(dataEntries); } var chartDataSetList = new List <BarChartDataSet>(); var k = 0; for (int i = 0; i < dataEntriesList.Count; i++) { var barChartDataSet = new BarChartDataSet(dataEntriesList[i].ToArray(), reportDataSet.labels[i]); if (dataEntriesList[i].ToArray().Length > 0) { barChartDataSet.SetColor(this.chartColors[k++]); } else { barChartDataSet.SetColor(UIColor.Clear); } barChartDataSet.ValueFormatter = new ChartDefaultValueFormatter(new NSNumberFormatter() { MinimumFractionDigits = 0, ZeroSymbol = "" }); barChartDataSet.ValueTextColor = UIColor.FromRGB(90, 89, 89); barChartDataSet.BarBorderColor = UIColor.FromRGB(90, 89, 89); chartDataSetList.Add(barChartDataSet); } var dataSets = chartDataSetList.ToArray(); var chartData = new BarChartData(dataSets); var initialXValue = 0; var groupSpace = 0.3; var barSpace = 0.05; var barWidth = (0.7 - (0.05 * optionsCount)) / optionsCount; // (barWidth + 0.05) * optionsCount + 0.3 = 1.00 -> interval per "group" chartData.BarWidth = barWidth; resultCell.barChartView.XAxis.AxisMinimum = initialXValue; resultCell.barChartView.XAxis.AxisMaximum = initialXValue + chartData.GroupWidthWithGroupSpace(groupSpace, barSpace) * groupCount; chartData.GroupBarsFromX(initialXValue, groupSpace, barSpace); resultCell.barChartView.Data = chartData; } resultCell.barChartView.AnimateWithXAxisDuration(1.4, ChartEasingOption.Linear); resultCell.barChartView.ChartDescription.Text = ""; resultCell.barChartView.NoDataText = "No results to show"; resultCell.AddSubview(resultCell.barChartView); resultCell.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|[v0]|", new NSLayoutFormatOptions(), "v0", resultCell.barChartView)); resultCell.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:|[v0(24)][v1]|", new NSLayoutFormatOptions(), "v0", resultCell.sectionLabel, "v1", resultCell.barChartView)); } return(resultCell); }
private void OnIntializeDataSet(Widget.Charts.Models.PieChart.IPieDataSet source, PieChartDataSet 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.AutomaticallyDisableSliceSpacing = (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.ToUIColor()); } 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.ValueLineVariableLength = (source.IF_GetValueLineVariableLength().Value); } if (source.IF_GetXValuePosition().HasValue) { original.XValuePosition = source.IF_GetXValuePosition().Value == Widget.Charts.Models.PieChart.ValuePosition.INSIDE_SLICE ? PieChartValuePosition.InsideSlice : PieChartValuePosition.OutsideSlice; } if (source.IF_GetYValuePosition().HasValue) { original.YValuePosition = source.IF_GetYValuePosition().Value == Widget.Charts.Models.PieChart.ValuePosition.INSIDE_SLICE ? PieChartValuePosition.InsideSlice : PieChartValuePosition.OutsideSlice; } }