1
votes

My requirements:

1) I need to draw a graph with date as xAxis and tracking result value as yAxis in which I need multiple points indicated for a day for different-2 time tracking and a scatter graph that is drawn on the basis of the average for that particular day as in iMoodJournal App.

enter image description here

2) I need to export the graph to image or customised pdf in which I need the full graph not only the graph that is displayed on the screen means I need the hidden part as scroll also in the image. I am succeeded to export to image as the graph is displaying on screen.

Thanks in advance

3

3 Answers

1
votes

Although this might not cater to all your requirements, but I would recommend LineGraph which serves first point.

Once you have the graph in a view, you can create memory bitmap and save it as UIImage.

EDIT:

Use below code to convert UIView to UIImage.

#import <QuartzCore/QuartzCore.h>

+ (UIImage *) imageWithView:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage * img = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return img;
}
1
votes

This is possible with Core Plot.

  1. There are many examples of line plots (scatter plots) in the example apps included with Core Plot. It has many options to customize the appearance of the graph.

  2. To make a graph larger than the screen, don't add it to a hosting view. Size the graph layer as big as you need and set up the plot space to show all of the data. Use the -imageOfLayer method to create an image of the graph or -dataForPDFRepresentationOfLayer to create a PDF.

0
votes

We can use the following code to take screen shot of the part of the graph which is not visible:

- (IBAction) renderScrollViewToImage
{
     UIImage* image = nil;

     UIGraphicsBeginImageContext(_scrollView.contentSize);
     {
         CGPoint savedContentOffset = _scrollView.contentOffset;
         CGRect savedFrame = _scrollView.frame;

         _scrollView.contentOffset = CGPointZero;
         _scrollView.frame = CGRectMake(0, 0, _scrollView.contentSize.width, _scrollView.contentSize.height);

         [_scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];     
         image = UIGraphicsGetImageFromCurrentImageContext();

         _scrollView.contentOffset = savedContentOffset;
         _scrollView.frame = savedFrame;
     }
     UIGraphicsEndImageContext();

     if (image != nil) {
         [UIImagePNGRepresentation(image) writeToFile: @"/tmp/test.png" atomically: YES];
         system("open /tmp/test.png");
}

}