Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPAndroidChart chart padding

I can't seem to enable padding on the horizontal BarChart in MPAndroidChart... Like on the screenshot below..the word commentary is cut off..even on tablets, both orientations e.t.c

like image 667
Bmbariah Avatar asked Dec 18 '15 07:12

Bmbariah


2 Answers

Have a look at the viewport documentation of the MPAndroidChart library.

There you find a method called setExtraOffsets(float left, float top, float right, float bottom) that allows to set additional offsets (as you require) for the chart.

like image 199
Philipp Jahoda Avatar answered Nov 11 '22 03:11

Philipp Jahoda


chart.minOffset = 0f
it will remove space on top/right/bottom/left, but it have 1 problem. A half of the HIGHEST label on left/right axis will above (overflow) another view on top)

chart.setViewPortOffsets(left, top, right, bottom)
it help us set the space in top/right/bottom/left but from the axis not from the label (eg: if we set left = 0 we will not see the label on the left). so if I only want to set the space on top only, this function is not suitable

chart.setExtraOffsets(left, top, right, bottom)
chart.extraTopOffset
chart.extraBottomOffset
chart.extraRightOffset

it helps us set space to top/right/bottom/left but it is the EXTRA space so to make it look as same as the design (eg: 40dp), I use

chart.extraTopOffset = getDimension(R.dimen_40dp) - chart.minOffset
like image 31
Linh Avatar answered Nov 11 '22 03:11

Linh