Reputation: 1586
I am creating a chart using MPAndroidChart library.
I see methods chart.getLowestVisibleXIndex()
and chart.getHighestVisibleXIndex()
to get the currently visible x-axis range.
But I need to get the currently visible y-axis range as well. Is that possible and if yes how can I do that?
Upvotes: 6
Views: 4017
Reputation: 51411
Yes, there is a pretty easy way to do that. All you need is an instance of your chart and it's ViewPortHandler
.
The ViewPortHandler
holds information about the current bounds of the chart and it's drawing area.
ViewPortHandler handler = mChart.getViewPortHandler();
PointD topLeft = mChart.getValuesByTouchPoint(handler.contentLeft(), handler.contentTop(), YAxis.AxisDependency.LEFT);
PointD bottomRight = mChart.getValuesByTouchPoint(handler.contentRight(), handler.contentBottom(), YAxis.AxisDependency.LEFT);
After executing this, the topLeft
point contains the minimum x-value and maximum y-value, the bottomRight
point contains the maximum x-value and the minimum y-value.
The AxisDependency
enum indicates from which axis you want to take the values from (in case you have both right and left YAxis
).
Upvotes: 7