Mpandroidchart: setVisibleXRangeMaximum not working as expected

Created on 26 Aug 2015  路  5Comments  路  Source: PhilJay/MPAndroidChart

Hi,

I am using the version 2.1.3 of this library, and I have live data (EMG signal) coming in that I process using LineChart.

The problem is that while trying to "zoomIn" on the most recent values, nothing seems to happen.

I have a dataset at any given point of 2K points (as given by getXValCount()), but if I do:

setVisibleXRangeMaximum(20), all of the points seem to show, and not only the latest 20 entries. If the purpose of this function different? What changes should I make?

Most helpful comment

I just found out, ordering matters for this to work. You need to call setVisibleXRangeMaximum after you invalidate or notifyDataSetChanged

All 5 comments

I am also interested in this feature. I want to show only 10 bars in BarChart using
barChart.setVisibleXRangeMaximum(10). But, interestingly, it shows all the bars.

I just found out, ordering matters for this to work. You need to call setVisibleXRangeMaximum after you invalidate or notifyDataSetChanged

@broncha Your solution seems to work, but the bar chart shows the first n entries, not the latest. That is scroll starts from left to right. How can we get it display data so that the latest n entries visible first and the scroll is from right to left.

moveViewTo(...) is what you are looking for. It's all in the documentation: https://github.com/PhilJay/MPAndroidChart/wiki/Modifying-the-Viewport

In my case it helped me chart.fitScreen() before chart.setVisibleXRangeMaximum(variable);

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Giammaofwar picture Giammaofwar  路  3Comments

AiTheAnswer picture AiTheAnswer  路  3Comments

tsengvn picture tsengvn  路  3Comments

SutharRohit picture SutharRohit  路  3Comments

vishvendu picture vishvendu  路  3Comments