This question is locked. New answers and comments are not allowed.
Hello,
I am having a problem with annotations. If I add an annotation in the ViewDidLoad along with Chart creation, it works. However if I add the annotation later...for example in a button press handler, it always shows up in the top left corner. I am using the latest Telerik.ui.for.Xamarin packages and latest Stable Xamarin Studio for Mac.
I have confirmed the behavior in the Examples provided on GitHub. For the View annotation, substitute the code below to reproduce.
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
TKChart chart = new TKChart (this.View.Bounds);
chart.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
this.View.AddSubview (chart);
Random r = new Random ();
for (int i = 0; i < 2; i++) {
List<TKChartDataPoint> list = new List<TKChartDataPoint> ();
for (int j = 0; j < 20; j++) {
list.Add(new TKChartDataPoint(new NSNumber(r.Next() % 1450), new NSNumber(r.Next() % 150)));
}
chart.AddSeries(new TKChartScatterSeries (list.ToArray()));
}
UIButton foo = new UIButton();
foo.SetTitle("Add Annotation", UIControlState.Normal);
foo.SetTitleColor(UIColor.Blue, UIControlState.Normal);
foo.UserInteractionEnabled = true;
this.View.AddSubview(foo);
foo.TranslatesAutoresizingMaskIntoConstraints = false;
foo.CenterXAnchor.ConstraintEqualTo(View.CenterXAnchor).Active = true;
foo.CenterYAnchor.ConstraintEqualTo(View.CenterYAnchor).Active = true;
foo.WidthAnchor.ConstraintEqualTo(100);
foo.HeightAnchor.ConstraintEqualTo(100);
this.View.BringSubviewToFront(foo);
foo.TouchUpInside += (sender, e) =>
{
// >> chart-layer-annotation-cs
UIImageView imageView = new UIImageView();
imageView.Image = UIImage.FromBundle("logo.png");
imageView.Bounds = new CGRect(0, 0, imageView.Image.Size.Width, imageView.Image.Size.Height);
imageView.Alpha = 0.7f;
chart.AddAnnotation(new TKChartViewAnnotation(imageView, new NSNumber(550), new NSNumber(90), chart.Series[0]));
// << chart-layer-annotation-cs
};
}
{
base.ViewDidLoad ();
TKChart chart = new TKChart (this.View.Bounds);
chart.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
this.View.AddSubview (chart);
Random r = new Random ();
for (int i = 0; i < 2; i++) {
List<TKChartDataPoint> list = new List<TKChartDataPoint> ();
for (int j = 0; j < 20; j++) {
list.Add(new TKChartDataPoint(new NSNumber(r.Next() % 1450), new NSNumber(r.Next() % 150)));
}
chart.AddSeries(new TKChartScatterSeries (list.ToArray()));
}
UIButton foo = new UIButton();
foo.SetTitle("Add Annotation", UIControlState.Normal);
foo.SetTitleColor(UIColor.Blue, UIControlState.Normal);
foo.UserInteractionEnabled = true;
this.View.AddSubview(foo);
foo.TranslatesAutoresizingMaskIntoConstraints = false;
foo.CenterXAnchor.ConstraintEqualTo(View.CenterXAnchor).Active = true;
foo.CenterYAnchor.ConstraintEqualTo(View.CenterYAnchor).Active = true;
foo.WidthAnchor.ConstraintEqualTo(100);
foo.HeightAnchor.ConstraintEqualTo(100);
this.View.BringSubviewToFront(foo);
foo.TouchUpInside += (sender, e) =>
{
// >> chart-layer-annotation-cs
UIImageView imageView = new UIImageView();
imageView.Image = UIImage.FromBundle("logo.png");
imageView.Bounds = new CGRect(0, 0, imageView.Image.Size.Width, imageView.Image.Size.Height);
imageView.Alpha = 0.7f;
chart.AddAnnotation(new TKChartViewAnnotation(imageView, new NSNumber(550), new NSNumber(90), chart.Series[0]));
// << chart-layer-annotation-cs
};
}
Thoughts?
Dan