Skip to content
This repository has been archived by the owner on Dec 2, 2020. It is now read-only.

Graph Snapshots

Samuel Spencer edited this page Aug 3, 2017 · 6 revisions

On iOS 7.0 and above you can take a snapshot of the line graph view and get a UIImage representation of the snapshot. To do so, simply call the method graphSnapshotImage after receiving a lineGraphDidFinishDrawing: call on the delegate.

- (void)lineGraphDidFinishDrawing:(BEMSimpleLineGraphView *)graph {
    // Update any interface elements that rely on a full rendered graph
    UIImage *imageOfGraph = [self.myGraph graphSnapshotImage];
}

The snapshot returned is not of the completed graph, but of the graph in its current state (regardless of whether it is in completely rendered). Use the lineGraphDidFinishDrawing: delegate method to find out when the graph has finished rendering and animating.

The returned UIImage is the size of the graph view's frame (in this example it would be the size of self.myGraph). Additionally, the returned image is in the current screen resolution.

WARNING Taking a graph snapshot before lineGraphDidFinishDrawing: is called may result in a nil or only partially rendered image. Take note of when you call this API.

Apple Watch

If you need to display a line graph in your WatchKit app, we recommend using this snapshot API to do so. Because WatchKit does not allow custom view objects, you must take a static snapshot of the graph and display it in a WKInterfaceImage object.

You can save snapshots like these to a shared location between your iOS app and your Watch app extension. Remember to resize, crop, and properly optimize your images before transferring them to your app extension.