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

。_饼干妹妹 提交于 2020-03-21 20:21:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!