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

Dynamic graph display #445

Closed
dayizhang opened this issue Oct 5, 2015 · 4 comments
Closed

Dynamic graph display #445

dayizhang opened this issue Oct 5, 2015 · 4 comments

Comments

@dayizhang
Copy link

Hi, I am using your library and use addEntry function to add data on the graph. The adding rate is about 80Hz, so 125 points per second. I set 400 points display on the window and remove entry outside window.
During the test on iPad mini, the whole app will be slower and slower after about 3 minutes. Maybe the library efficiency could be improved.

@danielgindi
Copy link
Collaborator

With your numbers, it means 22,500 data entries after 3 minutes. That will definitely draw slower.
Drawing the viewport as the end portion of the data, means the chart is looping over the data until reaching the data that is in the viewport. As it has no way to know which xIndex is inside the viewport without calculating it first.
We do have performance improvements planned, but it's not magic and sometimes we have to make compromises. In the meantime you can maybe remove some data that you are not using.

@dayizhang
Copy link
Author

Hi @danielgindi, thanks for this. I've already tried the approach you have mentioned, and as expected, there was a significant improvement in the performance. I was wondering maybe it would be of value to include this as a note in the docs regarding dynamic drawing?

@tulm00073
Copy link

I've got the exactly same function, update LineChartView about 100 times/second. But my problems is the graph seems not to update apparently, Could you point me out what's wrong with this? what is my mistake?

-> these lines of code will be call 100 times/sec
let chartDataSet = self.lineChartView.data?dataSets[0]
var index = chartDataSet?.valueCount

if index > MAX_XVALS {
chartDataSet.removeFirst()
index--
}

let entryData = ChartDataEntry(value: arc4random_uniform(1000) + 1, xIndex: index!)
chartDataSet.addEntry(entry)

self.lineChartView.notifyDataSetChanged()

Thank you.

@liuxuan30
Copy link
Member

@tulm00073 would you just check if the drawRect is called and the data you are sure it's updated.

Calling notifyDataSetChanged eventually will invoke setNeedsDisplay, so there should be a redraw of your line chart. You can debug from there.

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

No branches or pull requests

4 participants