I am using MPAndroidChart to create some line charts. Because the data are too many the chart is not clear enough and needs tapping and zooming.
Is there a way to set a max value of x-xalues to be displayed (e.g the 10 last ones) and display the others by scrolling?
I didnt find anything in the documentation. I only found the
setVisibleXRangeMaximum(float maxXRange): Sets the size of the area (range on the x-axis) that should be maximum visible at once. If this is e.g. set to 10, no more than 10 values on the x-axis can be viewed at once without scrolling.
function that is not available for line charts as I have noticed.
So what you want to do is always show 10 values in the chart, regardless of how many values are stored in the LineData object?
You can do that by restraining the view on the horizontal (x) axis and then aim the view at the data you want to be visible. Therefore, you need to call
chart.setVisibleXRangeMaximum(10); // allow 10 values to be displayed at once on the x-axis, not more
This will restrain the view on the x-axis and always show exactly 10 values. Then you can set where your view should aim at by calling
chart.moveViewToX(10);
If you call moveViewToX(10), your view will be aiming at the 10th position of x index.
Please let me know if this helped you.
Of course this method is available for LineCharts. Are you using the latest version v2.1.5 of the library?
Please check the release section on github and get the latest version. Then it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With