Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPAndroidChart MarkerView in fixed position

Is there any way to have fixed position for MarkerView? I need to have it fixed in top left or top right corner.

like image 516
Anish Manchappillil Avatar asked Mar 13 '23 10:03

Anish Manchappillil


1 Answers

This is one approach to fix the marker on the Top Left or Top Right

Once you've created the custom MarkerView here's what you can do.

1) You can set an id to the parent view/layout and using that id you can get it's width.

layoutWidth = customLayout.getWidth();

2) You can then override draw and do the following:

    @Override
    public void draw(Canvas canvas, float posX, float posY) {

        if (posX > (canvas.getWidth() / 2.0)) 
        //Check if the user is in the right half of the canvas
            super.draw(canvas, leftXPos, leftYPos); 
        //Draw marker on the left top corner


        else 
        //Otherwise draw the marker on the top right corner.
            super.draw(canvas, canvas.getWidth() - layoutWidth, rightYPos);
    }

You can set the values for leftXPos, leftYPos and rightYPos to whatever looks and feels best.

Hope this helps!

like image 157
Cid S Avatar answered May 16 '23 06:05

Cid S