Currently trying to implement a HorizontalBarChart using MPAndroidChart. However, there are too many bars and they won't all fit on the screen. HorizontalBarChart will scroll only if I zoom in, but will never go past what was already on the screen. Not sure if this is an XML problem (I have the HorizontalBarChart in a Relative Layout, tried ScrollView but didn't work) or if there's already an implementation like chart.enableScroll() (which I have tried, and it doesn't work).
Asked
Active
Viewed 9,368 times
2 Answers
21
You can use chart.setVisibleXRangeMaximum(10)
to control the number of entries that should be visible at once. If the chart contains more values, it will automatically allow scrolling.
More here: https://github.com/PhilJay/MPAndroidChart/wiki/Modifying-the-Viewport

Philipp Jahoda
- 50,880
- 24
- 180
- 187
-
Wow, PhilJay himself! Thank you! I used setVisibleYRangeMaximum instead (for some reason X did nothing - maybe because it was a HorizontalBarChart, but that fixed it – squeegene Oct 20 '15 at 02:54
-
Hi Squeegene, Could you please help me I want to show only 4 horizontal bars then it will scroll. But I am not able to do the same. – Rahul Vats Mar 30 '18 at 11:00
-
Hi, this setVisibleXRangeMaximum method now take floating values. Can someone guide me to achieve this in latest version of MPAndroidChart? – Anukool srivastav May 20 '19 at 05:27
-
9[IMPORTANT] use this solution after setData – Ali Zarei Jul 04 '20 at 09:51
-
1@AliZarei your comment was vital, thank you. – Eury Pérez Beltré Jan 13 '21 at 15:53
-
Thanks a lot, @AliZarei. Your comment was a cherry on top of it. – MashukKhan May 20 '22 at 00:58
3
chart.setData(...); // first set data
// now modify viewport
chart.setVisibleXRangeMaximum(5); // allow 5 values to be displayed
chart.moveViewToX(1);// set the left edge of the chart to x-index 1
You can use above way

fahrizal89
- 598
- 5
- 13