Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add padding on first and last label on x-axis in MPAndroidChart

I am using a Scatter Chart (MPAndroidChart library) and it looks like below presently.enter image description here

Everything works well so far except for the values on the first and last label (Su and S) wherein the circles are cut off. Is there a way to add padding so that Su has some padding on the left on the X Axis and renders the circle completely and S has some padding on the right so the circle values for S render completely. I have tried to manually set padding going through numerous examples but nothing has worked correctly so far. Is someone has any ideas and can point in the right direction it will be great.. Thanks!

like image 405
Abhishek Sabbarwal Avatar asked Jun 12 '17 22:06

Abhishek Sabbarwal


3 Answers

I just realized my previous answer isn't the best solution, but I'm going to leave it intact in case it better addresses certain situations or similar needs.

A better way to handle this is to use the SpaceMax and SpaceMin properties, which do exactly what you need without doing potentially fragile things with indices:

xAxis.setSpaceMax(0.1f);
xAxis.setSpaceMin(0.1f);

That will add the specified spacing on the ends in a much more clear and concise way.

like image 110
Ryan Avatar answered Oct 29 '22 18:10

Ryan


I would try setting offset on chart. This let me draw the full labels and dots on both sides, however the grid lines ends where the last dot is.

    mLineChart.setExtraLeftOffset(36);
    mLineChart.setExtraRightOffset(36);
like image 24
Andras_v Avatar answered Oct 29 '22 20:10

Andras_v


Use: xAxis.setAvoidFirstLastClipping(true)

If set to true, the chart will avoid that the first and last label entry in the chart "clip" off the edge of the chart or the screen.

like image 22
Brolin Michael Avatar answered Oct 29 '22 18:10

Brolin Michael