This is a migrated thread and some comments may be shown as answers.

Custom Annotation Example Doesn't Work For Me

1 Answer 37 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Carmen
Top achievements
Rank 1
Carmen asked on 07 Dec 2015, 06:11 PM

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

 

  

 

1 Answer, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 08 Dec 2015, 01:16 PM
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
Tags
Chart
Asked by
Carmen
Top achievements
Rank 1
Answers by
Todor
Telerik team
Share this question
or