Android: View Annotation - pixel value


#1

Hello,

I have a chart setup and everything is fine. Now i’m trying to show up a custom view on the Y axis and a view annotation doesn’t work for me because it’s added in the plot and i need to add the view on the Y axis.
So, the view is done and all good, next step is i’m trying to get the pixel coordinates for specific values in the charts. I’m using “getPixelValueForUserValue” method from the Y axis. The problem is this method complains when i pass to it the data point or any of its values - whether “MultiValueDataPoint<Date, Double>” or “DataPoint<Date, Double>”. I couldn’t find any examples or tutorials which includes usage of this method except for the API docs.

So, my questions is - is there any example or any directions anyone might have to pinpoint me how to use this and more specifically how to get the pixel coordinates of specific values?

To elaborate a little more - i’m trying to add a text view with custom background on the Y axis that will represent a certain value and will be stationary - meaning it will not change, but needs to move when the chart is moving, so that it stays on the same Y value.

P.S. : I have done this on iOS with the help of the equivalent method and all works just fine:
[chart.yAxis pixelValueForDataValue:<y-value of the data point>];

Cheers,
S.


#2

Hello Supudo.

Thanks for getting in touch. I am sorry to hear that you are having problem setting up your annotation to the Y axis. 

I’ve recently answered a post on another thread which covers a similar (but not identical) topic. Please have a look and see if this helps you :

In the meantime, can you please elaborate on what you mean when you say the method ‘complains’?

I look forward to hearing from you.

Thanks,

Kai.


#3

Thank you Kai!

The problem was that i was passing to getPixelValueForUserValue() either the whole data point or its getX() or getY(). Instead i should’ve passed to it Double object for example. This by itself wasn’t the issue, but couple with the way i was using the axis - instead of getting a specific NumberAxis (for ex.) i was using it by chart.getYAxis() and the error was :
“The method getPixelValueForUserValue(capture#37-of ?) in the type Axis<capture#37-of ?,capture#38-of ?> is not applicable for the arguments (Double)”

Cheers!