3

I am new user of MPAndroidChart in android. can any one help me ?

Philipp Jahoda
  • 50,880
  • 24
  • 180
  • 187
Nirav Alagiya
  • 721
  • 1
  • 5
  • 19

1 Answers1

17

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

setScaleMinima((float) lineData.getXValCount() / 10f, 1f)

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

centerViewPort(float val, int xindex)

If you call centerViewPort(500f, 11), your view will be aimed at the y-value 500 (vertical axis) and on the 11th value on the horizontal (x) axis.

Please let me know if this helped you.

UPDATE:

In newer versions of the library above 2.0.0, please refer the wiki on how to modify the viewport.

Philipp Jahoda
  • 50,880
  • 24
  • 180
  • 187
  • Thanks for the answer! One problem I have is the chart increasingly zooms. That means as I add more Entry, the chart display less and less points. Could you please help? Thanks! – Dũng Trần Trung Dec 23 '14 at 09:40
  • `chart.setVisibleXRangeMinimum(minBarsToShow)` should work as well, it's essentially `chart.setViewPortHandler().setMaximumScaleY(maxBars/minBarsToShow);` Just do it for the Max as well and you'll lock it. – CyberMew Jul 11 '16 at 08:21
  • 1
    `chart.moveViewToX(0);` just do nothing for me, after reseting BarData – Volodymyr Kulyk Nov 09 '16 at 11:55
  • In newer version of library, i.e 3.0.1 how can we put labels to x coordinates instead of showing the x value – swetabh suman Dec 30 '16 at 06:34