Custom Annotation Example Doesn't Work For Me

2 posts, 0 answers
  1. Carmen
    Carmen avatar
    10 posts
    Member since:
    Dec 2015

    Posted 07 Dec 2015 Link to this post

    annotation.setContentRenderer(new CustomTextRenderer()); 

    This line gives me an error "error: cannot find symbol
            annotation.setContentRenderer(new CustomTextRenderer());"

    From http://docs.telerik.com/devtools/android/controls/chart/chart-annotations

     

      

     

  2. Todor
    Admin
    Todor avatar
    778 posts

    Posted 08 Dec 2015 Link to this post

    Hi Carmen,

    Thank you for writing.

    Please make sure you have followed the whole paragraph from the documentation, namely that you have an annotation variable of type CartesianCustomAnnotation:
    CartesianCustomAnnotation annotation = new CartesianCustomAnnotation(verticalAxis, horizontalAxis, 6, "Feb", "TARGET");
    chartView.getAnnotations().add(annotation);

    Also, that you have your custom renderer defined:

    public class CustomTextRenderer implements CustomAnnotationRenderer {
        Paint contentPaint = new Paint();
     
        public CustomTextRenderer() {
            contentPaint.setTextSize(36);
            contentPaint.setColor(Color.RED);
            contentPaint.setTypeface(Typeface.create("sans-serif-light", Typeface.NORMAL));
        }
     
        @Override
        public RadSize measureContent(Object content) {
            if (content == null) {
                return RadSize.getEmpty();
            }
     
            String text = content.toString();
            Rect textBounds = new Rect();
            contentPaint.getTextBounds(text, 0, text.length(), textBounds);
     
            return new RadSize(textBounds.width(), textBounds.height());
        }
     
        @Override
        public void render(Object content, RadRect layoutSlot, Canvas canvas, Paint paint) {
            if (content == null) {
                return;
            }
     
            String text = content.toString();
            canvas.drawText(
                    text, (float) layoutSlot.getX() - (float) (layoutSlot.getWidth() / 2.0),
                    (float) layoutSlot.getBottom() - (float)layoutSlot.getHeight() / 2, contentPaint);
        }
    }

    And only then, you will be able to set the renderer as shown:

    annotation.setContentRenderer(new CustomTextRenderer());

    Let us know if you need further assistance.


    Regards,
    Todor
    Telerik
    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
  3. DevCraft banner
Back to Top