问题
I built a graph using MPAndroidChart, but there is a problem - values on x-axis overlap.
Is there a way to fix it? Something like a margin between x-axis values?
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/38360222/how-to-set-margin-padding-for-x-axis-values-in-mpandroidchart