繁体   English   中英

我们可以根据需要使用核心图或任何其他图形库绘制折线图吗?

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

我的要求:

1)我需要绘制一个日期为xAxis且跟踪结果值为yAxis的图形,其中我需要为一天中的多个2点时间跟踪指定多个点,并根据该特定值的平均值绘制散点图就像iMoodJournal App中一样。

在此处输入图片说明

2)我需要将图形导出到图像或定制的pdf,其中不仅需要显示在屏幕上的图形,还需要完整的图形,这意味着我还需要隐藏部分作为图像中的滚动部分。 当图形显示在屏幕上时,我成功导出到图像。

提前致谢

虽然这可能无法满足您的所有要求,但我还是建议使用LineGraph作为第一要点。

在视图中显示图形后,就可以创建内存位图并将其另存为UIImage。

编辑:

使用以下代码将UIView转换为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. Core Plot附带的示例应用程序中有许多折线图(散点图)示例。 它有许多选项可以自定义图形的外观。

  2. 要使图形大于屏幕, 请不要将其添加到托管视图中。 根据需要调整图形图层的大小,并设置绘图空间以显示所有数据。 使用-imageOfLayer方法创建图形图像,或使用-dataForPDFRepresentationOfLayer创建PDF。

我们可以使用以下代码对不可见的图形部分进行截屏:

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

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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