Custom Annotation Example Doesn't Work For Me

Thread is closed for posting
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());"





  2. Todor
    Todor avatar
    798 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");

    Also, that you have your custom renderer defined:

    public class CustomTextRenderer implements CustomAnnotationRenderer {
        Paint contentPaint = new Paint();
        public CustomTextRenderer() {
            contentPaint.setTypeface(Typeface.create("sans-serif-light", Typeface.NORMAL));
        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());
        public void render(Object content, RadRect layoutSlot, Canvas canvas, Paint paint) {
            if (content == null) {
            String text = content.toString();
                    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.

    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