I am new user of MPAndroidChart in android. can any one help me ?
-
What exactly do you mean by "auto-scroll"? – Philipp Jahoda Sep 09 '14 at 12:22
-
Thanks for reply,i want graph like stock graph. continues update in graph with scroll. – Nirav Alagiya Sep 09 '14 at 13:09
-
I dont fully understand. Could you explain in detail what it is you want to do? – Philipp Jahoda Sep 09 '14 at 20:07
-
Sorry for explanation, I am building app in which i want to show 10 point in line graph for ex. 1,2,---10. when i add 11th point in line graph my 1 point should be removed form graph but not removed form LineData. – Nirav Alagiya Sep 10 '14 at 12:29
1 Answers
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.

- 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