Incorrect Annotation Location

Thread is closed for posting
2 posts, 0 answers
  1. DAN
    DAN avatar
    4 posts
    Member since:
    Jun 2011

    Posted 18 Oct 2016 Link to this post


    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;


                foo.TranslatesAutoresizingMaskIntoConstraints = false;

                foo.CenterXAnchor.ConstraintEqualTo(View.CenterXAnchor).Active = true;
                foo.CenterYAnchor.ConstraintEqualTo(View.CenterYAnchor).Active = true;



                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


  2. Adrian
    Adrian avatar
    174 posts

    Posted 21 Oct 2016 Link to this post

    Hi, Dan,

    When you add the annotation runtime you should force an update by calling the UpdateAnnotations method of TKChart like in the snippet below:
    foo.TouchUpInside += (sender, e) =>
        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]));

    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top