public override void RangeChanged(SFDateTimeRangeNavigator rangeNavigator, NSDate startDate, NSDate endDate) { NSDateFormatter resultFormatter = new NSDateFormatter(); resultFormatter.DateFormat = "MMM dd"; lblTitle.Text = string.Format(@"Data usage cycle: {0} - {1}", resultFormatter.ToString(startDate), resultFormatter.ToString(endDate)); NSDateFormatter dateFormatter = new NSDateFormatter(); dateFormatter.DateFormat = @"MMM dd"; ChartDataModel data = new ChartDataModel(); NSDate date; NSNumber value; int y = 0; for (int i = 0; i < dataPoints.Count; i++) { data = dataPoints[i]; date = (CustomizationRangeNavigator.DateTimeToNSDate((DateTime)data.XValue)); if ((startDate.Compare(date) == NSComparisonResult.Ascending || startDate.Compare(date) == NSComparisonResult.Same) && (date.Compare(endDate) == NSComparisonResult.Ascending || date.Compare(endDate) == NSComparisonResult.Same)) { value = (NSNumber)data.YValue; y += (int)value; } } lblValue.Text = string.Format(@"Data usage - {0} MB", y); }
void Chart_LegendItemCreated(object sender, ChartLegendItemCreatedEventArgs e) { ChartDataModel dataModel = e.LegendItem.DataPoint as ChartDataModel; float heightAndWidth = Utility.IsIPad ? 80 : 60; UIView legendView = new UIView(); legendView.Frame = new CGRect(0, 0, 130, heightAndWidth - 10); SFChart legendChart = new SFChart(); legendChart.Frame = new CGRect(0, 0, heightAndWidth, heightAndWidth); UIImageView imageView = new UIImageView(); imageView.Image = UIImage.FromBundle(dataModel.Image); imageView.Frame = new CGRect(legendChart.Frame.X / 2, legendChart.Frame.Y / 2, Utility.IsIPad ? 30 : 20, Utility.IsIPad ? 30 : 20); SFDoughnutSeries series = new SFDoughnutSeries(); series.IsStackedDoughnut = true; series.Color = e.LegendItem.IconColor; series.ItemsSource = new List <ChartDataModel>() { dataModel }; series.XBindingPath = "XValue"; series.YBindingPath = "YValue"; series.StartAngle = -90; series.EndAngle = 270; series.MaximumValue = 100; series.Spacing = 0.2; series.DoughnutCoefficient = 0.8; series.CircularCoefficient = 1.0; series.CapStyle = DoughnutCapStyle.BothCurve; series.CenterView = imageView; legendChart.Series.Add(series); legendView.AddSubview(legendChart); UILabel yLabel = new UILabel(); yLabel.Frame = new CGRect(Utility.IsIPad ? 77 : 57, Utility.IsIPad ? 20 : 10, 80, 18); yLabel.TextColor = e.LegendItem.IconColor; yLabel.Font = UIFont.FromName("Helvetica", 14f); yLabel.Text = dataModel.YValue.ToString() + "%"; UILabel xLabel = new UILabel(); xLabel.Frame = new CGRect(Utility.IsIPad ? 77 : 57, Utility.IsIPad ? 40 : 30, 80, 18); xLabel.TextColor = UIColor.Black; xLabel.Font = UIFont.FromName("Helvetica", 12f); xLabel.Text = dataModel.XValue.ToString(); legendView.AddSubview(yLabel); legendView.AddSubview(xLabel); e.LegendItem.View = legendView; }
async void UpdateData() { await Task.Delay(50); if (!isDispose) { ChartDataModel datapoint = dataModel.dataPointWithTimeInterval(0.13); (chart.Series[0].ItemsSource as ObservableCollection <ChartDataModel>).Add(new ChartDataModel(datapoint.XValue, datapoint.YValue)); if (dataModel.verticalCount < 340) { UpdateData(); } } }