Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalidate method missing #2857

Open
adamstener opened this issue Oct 9, 2017 · 7 comments
Open

Invalidate method missing #2857

adamstener opened this issue Oct 9, 2017 · 7 comments

Comments

@adamstener
Copy link

This repo leaves the documentation up to the Android version of Charts, which is very similar, but with dynamic data or data refreshing, the Android repo says to call invalidate on the chart. There is no such method on this repo. How does one refresh the graph after modifying the data or dataset? Calling notify does not seem to do the trick.

@roxanajula
Copy link

roxanajula commented Oct 9, 2017

I was wondering the same, I have this issue on IOS charts: #2854 On Android it seems to be working fine and the only thing that is different in the code is the invalidate() function on Android. I also tried chartView.notifyDataSetChanged() and chartView.data.notifyDataChanged() but they don't seems to have the same effect as invalidate() has on Android.

@adamstener
Copy link
Author

I have the graph updating by adding the new item(s) to the dataSet, then calling these 3 methods.

DataSet.notifyDataSetChanged()
Data.notifyDataChanged()
Chart.notifyDataSetChanged()

@andrealufino
Copy link

As a workaround you could call chart.animate(xAxisDuration: 0.05) that redraws the chart (not in the correct way I guess).

@alum
Copy link

alum commented Oct 24, 2017

Solution by @adamstener works. As a matter of fact, only Chart.notifyDataSetChanged() is needed. However, I am updating the data by looping over the DataSet and doing something like:

let y = someMethodToGetNewDataPoint()
let entry = dataSet.entryForIndex(i)
entry?.y = y

@liuxuan30
Copy link
Member

liuxuan30 commented Oct 27, 2017

Data.notifyDataChanged() includes DataSet.notifyDataSetChanged() I think, because notifyDataSetChanged calls calcMinMax while Data.notifyDataChanged() will loop the data set to call it anyway.

But I found one improve here is not to loop all the time.

@dxshindeo
Copy link

Chart.notifyDataSetChanged() did the trick for me. My problem was that sometimes legends would go outside the chart, even though the wrapping was enabled. This fixed it.

@ghost
Copy link

ghost commented Nov 9, 2018

Ok, what worked me – I just cleared the array before adding new entries.

dataEntries.removeAll()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants