In my code I do a call to
mChart.moveViewToX(data.getXValCount() - 11);
mChart.invalidate();
I keep on adding data dynamically to the chart the above code is executed after each data addition.
Sometimes the chart does not change the viewport and after the next data, it changes.
I looked in the issue and I noted that if I call invalidate() once again after a second or so of adding the data then the chart moves. Upon further examining the issue, the found that the issue was due to not refreshing the chart upon completion of the post() job. In the _ViewPortHandler.java_ class, if I change the refresh(save, view, false); to refresh(save, view, true);, then my chart renders as desired. Is there any reason why you aren't refreshing after changing the viewport?
P.S. I am drawing a line chart, with multiple fill colours (i.e. one fill colour for dataset values above a specified limit and another fill colour for values below the limit) by using multiple datasets. IMO it would be an interesting demo to be added in your demo app. Let if know if I should send a pull request for the same :)
Are you doing anything different than this: https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/DynamicalAddingActivity.java ?
Because there it is working.
Yes its almost the same thing except that I am making the datasets with colour filled (so maybe slower rendering than the demo). Also in the demo (DynamicalAddingActivity.java), sometimes the viewport doesn't move to the next value on addition. I am testing it on samsung galaxy tab S, haven't checked on other devices.
I also wanted to know why isn't the view getting refreshed in the moveViewToX function. As far I could understand in the code, it's being executed in the View.post queue (the MoveViewJob class). So, if the next call to chart.invalidate() is called earlier than the callback of View.post job, then the chart will not be updated.
Hmmmm that's weird.
Is your chart in a regular activity? Or inside some fragment or custom view?
Yes, in a regular activity. Also when the viewport is not moving upon a particular data, if I touch/tap the screen before adding the next data, the viewport moves to the correct position, I guess this is because of invalidate being called on touch (which was not called earlier after the job completed callback)
.
Yes, that could be an issue, I will look into it
Please have another go at it now, I just pushed the (a possible) fix.
Great. Verified. Working smoothly.
:+1: fixed for me as well!
@PhilJay This fix doesn't work for me.
It only works on first time after I populate graph data. I call chart.moveViewToX(data.size() - 1) and the view port move to end (which is correct).
When I scroll to left, and call chart.moveViewToX(data.size() - 1) again, nothing happens (the graph data isn't changed)
And what if the chart is inside some fragment or custom view ?
It also stops working for me sometimes... I'm using the chart in a fragment.
mChartTemp.moveViewTo(mChartTemp.getData().getEntryCount() - 11,32f, YAxis.AxisDependency.LEFT);
This works fine for me
I found the reason why movieViewToX doesn't work is that computeScroll always call mChart.getViewPortHandler().refresh(); after movieViewToX().I changed the code by Override computeScroll method and movieViewToX worked again.
I found the reason why movieViewToX doesn't work is that computeScroll always call mChart.getViewPortHandler().refresh(); after movieViewToX().I changed the code by Override computeScroll method and movieViewToX worked again.
same problem :D
so i make isDragDecelerationEnabled = false
this way temporary worked for me
I have the same issue when BarChart is an item of a ViewPager. In this case, moveViewToX() works only for the first item. Is any available solution for this problem?
In my case, I'm trying to improve my code, I mean making it more robust.
On Fri, Mar 1, 2019, 09:38 Kostya Bakay notifications@github.com wrote:
I have the same issue when BarChart is an item of a ViewPager. In this
case, moveViewToX() works only for the first item. Is any available
solution for this problem?—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/PhilJay/MPAndroidChart/issues/765#issuecomment-468651651,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AefcyxnxyT8i_OlBSbEIseq8s7P4JRnRks5vSR9XgaJpZM4FDN4Z
.
In my case, I'm trying to improve my code, I mean making it more robust.
Okay, so is it a known issue for the chart as an element of ViewPager?
Most helpful comment
@PhilJay This fix doesn't work for me.
It only works on first time after I populate graph data. I call
chart.moveViewToX(data.size() - 1)and the view port move to end (which is correct).When I scroll to left, and call
chart.moveViewToX(data.size() - 1)again, nothing happens (the graph data isn't changed)