MPAndroidChart避免数据点的标签剪切

时间:2021-08-24 09:34:55

I have a problem with the MPAndroidChart library I use for my Android project. It seems that the first entry of my charts gets cut off since the value is too large (see screen shot). The value of the first entry point is 106.6 however only the 06.6 is visible. Is there any option to avoid this?

我的Android项目使用的MPAndroidChart库有问题。似乎我的图表的第一个条目因为值太大而被切断(参见屏幕截图)。第一个入口点的值是106.6,但只有06.6可见。有没有选择避免这种情况?

I already found the setAvoidFirstLastClipping(boolean) of the xAxis but this doesn't solve my problem.

我已经找到了xAxis的setAvoidFirstLastClipping(boolean),但这并没有解决我的问题。

MPAndroidChart避免数据点的标签剪切

2 个解决方案

#1


7  

Thanks to Philipp Jahoda's comment I solved the problem. I just had to add an extra offset to the left and the right of the chart.

感谢Philipp Jahoda的评论,我解决了这个问题。我只需要在图表的左侧和右侧添加一个额外的偏移量。

mChart.setExtraLeftOffset(15);
mChart.setExtraRightOffset(15);

#2


1  

I don't have much experience with MPAndroidChart, but here's what you can try. If you have padding in your chart, you can set android:clipToPadding="false", so that the chart can draw over padding area. Additionally you can set android:clipChildren="false" on chart's parent view so that it can draw beyond its view borders without clipping.

我对MPAndroidChart没有多少经验,但这是你可以尝试的。如果你的图表中有填充,你可以设置android:clipToPadding =“false”,这样图表就可以绘制填充区域。此外,您可以在图表的父视图上设置android:clipChildren =“false”,以便它可以绘制超出其视图边框而不剪切。

However, first of all this won't add any insets to the chart, meaning that you'll lose symmetry, and very long values will still clip by your screen. Also, if MPAndroidChart doesn't draw directly to Canvas but to the temporary bitmap (which was the case IIRC), these attributes won't help.

但是,首先这不会在图表中添加任何插入,这意味着您将失去对称性,并且很长的值仍然会被屏幕剪切。此外,如果MPAndroidChart不直接绘制到Canvas而是绘制到临时位图(例如IIRC),这些属性将无济于事。

#1


7  

Thanks to Philipp Jahoda's comment I solved the problem. I just had to add an extra offset to the left and the right of the chart.

感谢Philipp Jahoda的评论,我解决了这个问题。我只需要在图表的左侧和右侧添加一个额外的偏移量。

mChart.setExtraLeftOffset(15);
mChart.setExtraRightOffset(15);

#2


1  

I don't have much experience with MPAndroidChart, but here's what you can try. If you have padding in your chart, you can set android:clipToPadding="false", so that the chart can draw over padding area. Additionally you can set android:clipChildren="false" on chart's parent view so that it can draw beyond its view borders without clipping.

我对MPAndroidChart没有多少经验,但这是你可以尝试的。如果你的图表中有填充,你可以设置android:clipToPadding =“false”,这样图表就可以绘制填充区域。此外,您可以在图表的父视图上设置android:clipChildren =“false”,以便它可以绘制超出其视图边框而不剪切。

However, first of all this won't add any insets to the chart, meaning that you'll lose symmetry, and very long values will still clip by your screen. Also, if MPAndroidChart doesn't draw directly to Canvas but to the temporary bitmap (which was the case IIRC), these attributes won't help.

但是,首先这不会在图表中添加任何插入,这意味着您将失去对称性,并且很长的值仍然会被屏幕剪切。此外,如果MPAndroidChart不直接绘制到Canvas而是绘制到临时位图(例如IIRC),这些属性将无济于事。