Orest
Orest

Reputation: 6748

How to set margin/padding for x-axis values in MPAndroidChart?

I built a graph using MPAndroidChart, but there is a problem - values on x-axis overlap. enter image description here

Is there a way to fix it? Something like a margin between x-axis values?

Upvotes: 6

Views: 11111

Answers (2)

Arwen
Arwen

Reputation: 435

It's been a while since you've posted your question and probably by now you found your way around this problem, however, I'm posting this answer for anyone else who has faced this issue.

Setting

chart.getXAxis().setSpaceMin(0.5f);

would add space between the X-axis line and the chart itself. you can also use

chart.getXAxis().setSpaceMax(0.5f);

for adding space between the last value and the right X-axis of the chart.

Here is an example of a normal chart and this one is a chart with min and max space of 1.5.

By the way, I'm using MPAndroidChart V3.0.2.

Upvotes: 13

Albert
Albert

Reputation: 343

Try

 XAxis xAxis = chart.getXAxis();
 xAxis.setSpaceBetweenLabels(int characters) //Sets the space that should be left out between the x-axis labels in characters, default: 4.

Upvotes: 0

Related Questions