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

LineChart set a great amount data to LineChartDataSet, cpu increase highly to 97% #1063

Closed
dogvscat opened this issue May 23, 2016 · 15 comments

Comments

@dogvscat
Copy link

`var yVals = ChartDataEntry
for yIndex in 0..<count {
yVals.append(ChartDataEntry(value: Double(value[yIndex]), xIndex: yIndex))
}

let lineChartDataSet = LineChartDataSet(yVals: yVals, label: "Audio Wave")
lineChartDataSet.drawCubicEnabled = true
lineChartDataSet.cubicIntensity = 0.2
lineChartDataSet.drawCirclesEnabled = false
lineChartDataSet.lineWidth = 1.8
lineChartDataSet.circleRadius = 4.0
lineChartDataSet.circleColors = [UIColor.whiteColor()]
lineChartDataSet.colors = [UIColor.greenColor()];
lineChartDataSet.fillColor = UIColor.whiteColor();
lineChartDataSet.fillAlpha = 1.0;
lineChartDataSet.drawHorizontalHighlightIndicatorEnabled = false
lineChartDataSet.drawVerticalHighlightIndicatorEnabled = true
lineChartDataSet.highlightColor = UIColor.whiteColor()
lineChartDataSet.highlightLineWidth = 2.0

    let lineChartData = LineChartData(xVals: xVals, dataSet: lineChartDataSet)

`
and count may be a great number.while i setLineData,the cpu and memeory rise up highly

@danielgindi
Copy link
Collaborator

danielgindi commented May 26, 2016

Currently CoreGraphics is rendering over the CPU instead of the GPU. This is slow.
I hope to create a simple 2D drawing layer over GPU, but there's no ETA for that...
We discussed this a bit on #29 .

There are other solutions. As in most cases - it's wrong anyway to add thousands of datapoints.
You can approximate a lower resolution of that dataset and feed that to the chart. Or limit scale and only show a certain number of datapoints at a time.

@dogvscat
Copy link
Author

dogvscat commented Jun 6, 2016

  1. "huge numbers of datapoints (10K or more)" - we are working on it :) I can't say about Android, as moving it to GL will be an even bigger PITA, but it is already having pretty good performance by leveraging the hardware layer, which is doing all drawing on the GPU. so when will you move it to GL?
  2. as dorsoft said "I've managed to make a candle stick chart with 10k data points pan/zoom smoothly. by changing CandleStickChartRenderer.swift, line 76,77 from:
    var minx = max(dataSet.entryIndex(entry: entryFrom, isEqual: true), 0);
    var maxx = min(dataSet.entryIndex(entry: entryTo, isEqual: true) + 1, entries.count);
    to
    var minx = max(_minX, 0);
    var maxx = _maxX + 1;"
    i modify this in linechart, but it seems to be no effect on cpu or memory.
  3. limit scale and only show a certain number of datapoints at a time.
    i have set the maxVisibleValueCount to 20, and drawValues to be true,but it also does not work. Any idea ?

@liuxuan30
Copy link
Member

liuxuan30 commented Jun 6, 2016

Towards second one, have you checked dataSet.entryIndex(entry: entryFrom, isEqual: true)'s time complexity? I am on a windows machine now so I can't see it. If it's O(1), then the change should not impact the performance.
For the third one, I guess Daniel means you have to reduce entries in your data sets? I don't remember how many loops will check maxVisibleValueCount. If some loops are still walking through all your data, it should be slow?

@dogvscat
Copy link
Author

@liuxuan30 i haven't tested it, and now i still don't know how to solve my problem. Android uses idea of point 3 to solve this problem. so i wonder how to use this properly with iOS? @danielgindi

@woolfel
Copy link

woolfel commented Aug 10, 2016

Has anyone else found a work around for rendering charts with more than 10K datapoints? I can render charts with 1-3K datapoints fine, but more than that it's very slow. With more than 36K datapoints, it never responds. thanks.

@liuxuan30
Copy link
Member

liuxuan30 commented Aug 12, 2016

I do think performance is issue, but right now you could use 3.6K or 360 to render..? sampling won't affect the chart shape a lot I think

@woolfel
Copy link

woolfel commented Aug 12, 2016

I know it's a bit excessive. It's accelerometer and gyroscope data recorded by the phone. I've thought of a few work arounds, but wanted to see what other solutions people have tried. The most obvious is to only show 1000 datapoints and use swipe gesture to scroll through the dataset.

@danielgindi
Copy link
Collaborator

CoreGraphics cannot handle 36K of datapoints. We may use a different rendering engine to solve that- but you still need to use less datapoints.

There's no user who can make use of this amount of data in a chart.

You need to approximate the data, like GitHub does on their statistic charts on the site.

@woolfel
Copy link

woolfel commented Aug 12, 2016

thanks for taking time to respond. I thought about averaging, smoothing or other ways of approximating the data. I was curious to see what others have tried with crazy large datasets. thanks

@danielgindi
Copy link
Collaborator

Well one way or another- approximating is the way to go.
Think about it this way: How will 36,000 points will look on a 400-500 px wide screen?
The answer is- it will look like 400-500 points.

Take a look at the DataApproximator in Charts.
It is actually implemented better in v3, where there are real x values.

@woolfel
Copy link

woolfel commented Aug 12, 2016

thanks, I will take a look at DataApproximator.

@woolfel
Copy link

woolfel commented Aug 13, 2016

I just clone the latest version and didn't see an example using DataApproximator. If there isn't one, I'm happy write a sample and make a pull request. Thanks

@danielgindi
Copy link
Collaborator

There isn't one, you are welcome to create one!
בתאריך שבת, 13 באוג׳ 2016 ב-14:43 מאת Peter Lin notifications@github.com:

I just clone the latest version and didn't see an example using
DataApproximator. If there isn't one, I'm happy write a sample and make a
pull request. Thanks


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#1063 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAWZTg6TjoX_aFAq0oskorJDj2icZ5KOks5qfa35gaJpZM4IkbAL
.

@UnAmico0
Copy link

thanks, I will take a look at DataApproximator.

Have you solved this problem?

@goors
Copy link

goors commented Jun 5, 2023

Same here 5000 points ... cpu 100%

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

6 participants