【问题标题】:Coreplot Library - Extract entire graph imageCoreplot 库 - 提取整个图形图像
【发布时间】:2012-02-22 09:24:34
【问题描述】:

我正在使用此代码为图形创建图像

UIImage *newImage=[graph imageOfLayer]
NSData *newPNG= UIImageJPEGRepresentation(newImage, 1.0); 
NSString *filePath=[NSString stringWithFormat:@"%@/graph.jpg",     [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]];           
if([newPNG writeToFile:filePath atomically:YES])
NSLog(@"Created new file successfully");

但是我在图像中只得到可见区域(320 * 460),我怎样才能得到带有轴的整个图形图像。 请提供一些代码sn-p,我该如何使用coreplot。

提前致谢...

【问题讨论】:

    标签: iphone graph core-plot


    【解决方案1】:

    制作一个与所需输出图像大小相同的新图表。不必将其添加到托管视图中,只需将其显示在屏幕上即可。

    CPTXYGraph *graph = [(CPTXYGraph *)[CPTXYGraph alloc] initWithFrame:desiredFrame];
    // set up the graph as usual
    UIImage *newImage=[graph imageOfLayer];
    // process output image
    

    【讨论】:

    • 我不只想要可见区域图..我也想要不可见图..滚动...即我得到了 320 X 460 的图形,我在屏幕上看到了它,但我想要整个图形,我用滚动条看到......不仅仅是增加框架......而是整个图形............例如我想要 Xaxis 10到 200 ..我在屏幕上只看到 10 到 100 ......另一个 101 到 200 在滚动中..那么如何获得 10 到 200 的整个图像 ..
    • 设置大屏幕外图表时,设置绘图范围以显示您想要查看的所有数据。
    • OK 需要更多帮助...我在 Xaxis 中添加一个标签..使用此代码..NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:[xAxisLabels count]]; for (NSNumber *tickLocation in customTickLocations) { CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText: [xAxisLabels objectAtIndex:labelLocation++] textStyle:XtextStyle]; newLabel.tickLocation = [tickLocation decimalValue]; newLabel.offset = x.labelOffset + x.majorTickLength; newLabel.rotation = M_PI/4; [customLabels addObject:newLabel]; [新标签发布]; }
    • 如何在 X 轴上添加 2 个标签..因为我想在 X 轴上显示日期和时间..谢谢您的帮助..
    • 您可以通过在它们之间插入换行符 ('\n') 将日期和时间放在不同的行上。使用文本样式的textAlignment 属性来控制对齐方式(左、中、右)。
    【解决方案2】:

    我解决这个问题的方法是创建一种方法来提取图像。

    在该方法中,我暂时使宿主视图、滚动视图、图形边界和绘图区域框架边界暂时变大。然后我将图表转换为图像。

    然后我从其容器中删除托管视图以将其从屏幕中删除。然后我调用 doPlot 方法通过 DoPlot 方法重新初始化绘图及其数据。我的代码如下。

    执行此操作时可能会出现视觉抖动。但是,您总是可以通过使用警报来伪装这一点,或者输入要导出的电子邮件,或者只是一个简单的警报,说图像已导出。

    //=============================================================================
    /**
     Gets the image of the chart to export via email.
     */
    //=============================================================================
    -(UIImage *) getImage
    {
    
        //Temprorarilty make plot bigger.
        // CGRect rect =  self.hostingView.bounds;
        CGRect rect =  self.scroller.bounds;
        rect.size.height = rect.size.height -100;
    
        rect.origin.x = 0;
        rect.size.width = rect.size.width + [fields count] * 100.0;
        [self.hostingView setBounds:rect];
        [scroller setContentSize:  hostingView.frame.size];
        graph.plotAreaFrame.bounds = rect;
        graph.bounds = rect;
    
    
        UIImage * image =[graph imageOfLayer];//get image of plot.
    
    
        //Redraw the plot back at its normal size;
        [self.hostingView removeFromSuperview];
        self.hostingView = nil;
        [self doPlot];
    
         return image;
    }//============================================================================
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-02
      相关资源
      最近更新 更多