在Core plot iOS中以散点图符号形式显示散射图上的图像 [英] Showing images on Scattering Graph as plot symbols in Core plot iOS
问题描述
我有要求在散射图中的图形符号处显示图像。现在我正在使用CPTPlotSymbol在图上绘制符号。但我所能得到的只是预定义的对象。例如。 ellipsePlotSymbol,dashPlotSymbol,trianglePlotSymbol。
但是我需要绘制一张图片。
你能帮我吗?实现这一点。
尝试了一下后得到了答案。
首先,我构建了一个自定义CPTLayer,并在其中使用该图像进行填充。
$ b CustomImageForScatterPlot.h文件
#importCPTLayer.h
@interface CustomImageForScatterPlot:CPTLayer
{
UIImage * _image;
- (id)initWithImage:(UIImage *)image;
@end
CustomImageForScatterPlot.m文件
#importCustomImageForScatterPlot.h
#importCPTLayer.h
@implementation CustomImageForScatterPlot
- (void)dealloc {
[_image release];
[super dealloc];
- (id)initWithImage:(UIImage *)image {
CGRect f = CGRectMake(0,0,image.size.width,image.size.height) ;
if(self = [super initWithFrame:f]){
_image = [image retain];
}
返回自我;
$ b - (void)drawInContext:(CGContextRef)ctx {
CGContextDrawImage(ctx,self.bounds,_image.CGImage);
@end
现在,在散点图(CPTLayer *)dataLabelForPlot:(CPTPlot *)plot recordIndex图表文件,我用下面的委托方法返回图像
- :(NSUInteger)index
{
CustomImageForScatterPlot * layer = [[CustomImageForScatterPlot alloc] initWithImage:[UIImage imageNamed:@dots.png]];
layer.frame = CGRectMake(2,0,34,6);
返回图层;
}
ENJOY CODING ....:)
I have a requirement of showing images at the plot symbols in my scattering Graph. Right now I am using CPTPlotSymbol to plot symbols on the graph. But all I can get with it are the predefined objects. Eg. ellipsePlotSymbol, dashPlotSymbol, trianglePlotSymbol.
But I need to plot an image instead.
Could you help me in acheiving this. Thanks a lot.
Got the answer after trying a bit.
First of all, I built a Custom CPTLayer and inside it used the image to be filled.
CustomImageForScatterPlot.h file
#import "CPTLayer.h"
@interface CustomImageForScatterPlot : CPTLayer
{
UIImage *_image;
}
-(id)initWithImage:(UIImage *)image;
@end
CustomImageForScatterPlot.m file
#import "CustomImageForScatterPlot.h"
#import "CPTLayer.h"
@implementation CustomImageForScatterPlot
-(void)dealloc{
[_image release];
[super dealloc];
}
-(id)initWithImage:(UIImage *)image{
CGRect f = CGRectMake(0, 0, image.size.width, image.size.height);
if (self = [super initWithFrame:f]) {
_image = [image retain];
}
return self;
}
-(void)drawInContext:(CGContextRef)ctx{
CGContextDrawImage(ctx, self.bounds, _image.CGImage);
}
@end
NOW, in the Scatter plot graph file, I used the following delegate method to return the images
- (CPTLayer *)dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)index
{
CustomImageForScatterPlot* layer = [[CustomImageForScatterPlot alloc] initWithImage:[UIImage imageNamed:@"dots.png"]];
layer.frame = CGRectMake(2, 0, 34, 6);
return layer;
}
ENJOY CODING.... :)
这篇关于在Core plot iOS中以散点图符号形式显示散射图上的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!