Chart snapshot in sChartRenderFinished



I try to get a snapshot of my charts under iOS7, I naturally do it in sChartRenderFinished

It is properly called, but snapshot I get is an empty image (of right size). Here is the code

Thanks for any help


CGContextRef context = UIGraphicsGetCurrentContext();
        if ([_chart respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)]) {
                [_chart drawViewHierarchyInRect:_chart.bounds afterScreenUpdates:YES];
            } else {
                [_chart.layer renderInContext:context];
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        NSLog(@"Size height %f width %f", image.size.height, image.size.width); // we get proper image size
        NSData *imageData = UIImagePNGRepresentation(image); //convert image into .png format.
        NSFileManager *fileManager = [NSFileManager defaultManager];//create instance of NSFileManager
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //create an array and store result of our search for the documents directory in it
        NSString *documentsDirectory = [paths objectAtIndex:0]; //create NSString object, that holds our exact path to the documents directory
        NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", @"chart"]]; //add our image to the path
        [fileManager createFileAtPath:fullPath contents:imageData attributes:nil]; //finally save the path (image)
        NSLog(@"image saved"); // image is empty


Any news about this issue ?


Hey NeoSylvain,

Our chart’s are rendered in OpenGL, so taking a snapshot isn’t that simple unfortunately! We have a blog post that covers how to do this, here’s the link.


Jan Akerman


Thanks, I get the graph, I just have issues with the annotations which are cut (both in width and height)


Hi NeoSylvain,

We’ve updated the blog post to talk about iOS7 methods of snapshotting:

Does this fix the issues with the annotations?


No it doesn’t

It seems the snapshot doesn’t take into account those changes:

CGRect f = annotationMoyenne.label.frame;
f.origin.x = f.origin.x + f.size.width/2.f;
f.origin.y = f.origin.y - f.size.height/2.f;
annotationMoyenne.label.frame = f;