BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
public class CustomDelegate : SFChartDelegate
{
public override NSString GetFormattedDataMarkerLabel(SFChart chart, NSString label, nint index, SFSeries series)
{
return (NSString)"Label";
}
} |
Hi Parthiban,
Thanks a lot for this suggestion as it really helped me, though partially. Now I am able to place the marker in the centre the contents of its marker is not getting centrally align.
As I want to align both the data marker as well as data marker label in the centre, and I am using "" between the strings ,So the value comes in the next line.
here is the code snippet:
public override NSString GetFormattedDataMarkerLabel(SFChart chart, NSString label, nint index, SFSeries series)
{
SFDoughnutSeriesExtension series1 = (SFDoughnutSeriesExtension)series;
string lTitle = series1.Demands[(int)index].Demand.Trim();
string lValue = series1.Demands[(int)index].Year2010.ToString();
return (NSString)(lValue + "" + lTitle);
}
I Have attached a screenshot of the chart, kindly look into it for the reference.
Thanks In advance, hope to get the solution asap.
Regards,
bacca.
Hi Parthiban,
Thanks a lot for this suggestion as it really helped me, though partially. Now I am able to place the marker in the centre, but the contents of its marker label is not getting centrally align.
As I want to align both the data marker as well as data marker label in the centre, and I am using "" between the strings values ,So the value comes in the next line and gets left aligned.
As I don't have to display them in a single line.
here is the code snippet:
public override NSString GetFormattedDataMarkerLabel(SFChart chart, NSString label, nint index, SFSeries series)
{
SFDoughnutSeriesExtension series1 = (SFDoughnutSeriesExtension)series;
string lTitle = series1.Demands[(int)index].Demand.Trim();
string lValue = series1.Demands[(int)index].Year2010.ToString();
return (NSString)(lValue + "" + lTitle);
}
I Have attached a screenshot of the chart, kindly look into it for the reference.
Thanks In advance, hoping to get the solution asap.
Regards,
bacca.
Hi Parthiban,
I have edited the code of your project ,
below is the code reference and a screenshot.
public override void ViewDidLoad()
{
base.ViewDidLoad();
chart = new SFChart();
DataPoints = new ObservableCollection<ChartModel>()
{
new ChartModel("January", 30),
new ChartModel("February", 30),
new ChartModel("March", 30),
new ChartModel("April", 30),
new ChartModel("June", 30),
};
chart.Frame = new CoreGraphics.CGRect(0, 0, View.Frame.Width, View.Frame.Height);
SFDoughnutSeries series = new SFDoughnutSeries();
series.ItemsSource = DataPoints;
series.XBindingPath = "XValue";
series.YBindingPath = "YValue";
series.DataMarker.ShowLabel = true;
series.DataMarker.LabelContent = SFChartLabelContent.YValue;
series.DataMarker.LabelStyle.BackgroundColor = UIColor.Clear;
series.DataMarker.LabelStyle.Color = UIColor.White;
series.DataMarkerPosition = SFChartCircularSeriesLabelPosition.Inside;
series.DataMarker.LabelStyle.LabelPosition = SFChartDataMarkerLabelPosition.Center;
chart.Series.Add(series);
chart.Delegate = new CustomDelegate();
View.AddSubview(chart);
}
public override void ViewDidLayoutSubviews()
{
base.ViewDidLayoutSubviews();
}
}
public class CustomDelegate : SFChartDelegate
{
public override NSString GetFormattedDataMarkerLabel(SFChart chart, NSString label, nint index, SFSeries series)
{
ObservableCollection<ChartModel> DataPoints = new ObservableCollection<ChartModel>();
DataPoints = (System.Collections.ObjectModel.ObservableCollection<RealTimeData.ChartModel>)series.ItemsSource;
return (NSString)(DataPoints[(int)index].YValue.ToString() + "" + DataPoints[(int)index].XValue.ToString());
}
}
As per the screenshot, I want that "30" should be centrally aligned wrt all the Months as now it is at the left.
Regards,
Baccca
public override UIView ViewForDataMarkerLabel(SFChart chart, NSString label, nint index, SFSeries series)
{
var dataPoints = (series.ItemsSource as IList<ChartModel>);
UIView customView = new UIView();
customView.Frame = new CGRect(0, 0, 80, 20);
UILabel label1 = new UILabel();
label1.Frame = new CGRect(3, 0, 60, 20);
label1.Text = (NSString)(dataPoints[(int)index].YValue.ToString());
label1.TextColor = UIColor.White;
label1.Font = UIFont.FromName("Helvetica", 12f);
label1.TextAlignment = UITextAlignment.Center;
UILabel label2 = new UILabel();
label2.Frame = new CGRect(3, 20, 60, 20);
label2.Text = (NSString)(dataPoints[(int)index].XValue);
label2.Font = UIFont.FromName("Helvetica", 12f);
label2.TextColor = UIColor.White;
label2.TextAlignment = UITextAlignment.Center;
customView.AddSubview(label1);
customView.AddSubview(label2);
return customView;
} |
Hi Parthiban,
I followed your steps, but due to recreation of outlets, there occurs memory leakage and sometimes SIGSEV error is shown and app crashes immediately.
Also you have used both the extension as well as the delegate method.
Do I also need to implement both these methods, as currently I am using only the delegate one.
Regards,
bacca.