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

drawCubicEnabled performance issues #717

Closed
arjunnayak opened this issue Jan 27, 2016 · 1 comment
Closed

drawCubicEnabled performance issues #717

arjunnayak opened this issue Jan 27, 2016 · 1 comment

Comments

@arjunnayak
Copy link

Like many others have mentioned, I'd like to thank anyone involved in the development of this library. It's saved me an incredible amount of time at work, and has inspired me to get more involved in the open source community!

I'm currently using a relatively simple use of a LineChartView to display a fully zoomed out graph of ~350 data points. However, even in the ChartsDemo example with LineChart1ViewController, I've noticed that when I use:
lineChartDataSet.drawCubicEnabled = YES;
the performance on the graph tends to considerably decrease.

I'm testing with the LineChart1ViewController code with very slight modifications:

- (void) setChartDataWithData: (NSArray *) data {

    NSMutableArray *xVals = [[NSMutableArray alloc] init];

    for (int i = 0; i < data.count; i++)
    {
        [xVals addObject:[@(i) stringValue]];
    }

    NSMutableArray *yVals = [[NSMutableArray alloc] init];

    for (int i = 0; i < data.count; i++)
    {
        double mult = (90 + 1);
        double val = (double) (arc4random_uniform(mult)) + 3;
        [yVals addObject:[[ChartDataEntry alloc] initWithValue:val xIndex:i]];
    }

    LineChartDataSet *set1 = [[LineChartDataSet alloc] initWithYVals:yVals label:@"DataSet 1"];
    set1.highlightColor = [UIColor redColor];
    set1.highlightLineWidth = 2.0f;
    [set1 setColor:UIColor.blackColor];
    [set1 setCircleColor:UIColor.blackColor];
    set1.lineWidth = 1.0;
    set1.circleRadius = 3.0;
    set1.drawCircleHoleEnabled = NO;
    set1.valueFont = [UIFont systemFontOfSize:9.f];
    set1.fillAlpha = 65/255.0;
    set1.fillColor = UIColor.blackColor;
    set1.drawCubicEnabled = YES;

    NSMutableArray *dataSets = [[NSMutableArray alloc] init];
    [dataSets addObject:set1];

    LineChartData *chartData = [[LineChartData alloc] initWithXVals:xVals dataSets:dataSets];

    _lineChartView.data = chartData;

}

@danielgindi
Copy link
Collaborator

There are cases where many data points will cause performance degradation. That's just a fact that there's more to process. Specifically when drawing cubic lines, there's more for the CPU to calculate to find the position of each pixel.

I did try in the past to move the drawing to the GPU (as CoreGraphics draws mainly using the CPU), but haven't had the time yet to check more options that were suggested.

We have a discussion that's been sleepy for a while, here: #29

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

2 participants