简体   繁体   中英

Can we draw a line graph using core plot or any other graph library with my requirement?

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.

在此处输入图片说明

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

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;
}

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.

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");
}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM