Display images on a scatter chart as graphic symbols in Core plot iOS

I have a requirement to show images on graphs in my scatter plot. Right now I'm using CPTPlotSymbol to plot symbols on a chart. But all I have are predefined objects. For instance. ellipsePlotSymbol, dashPlotSymbol, trianglePlotSymbol.

But I need to build an image instead.

Could you help me with this. Many thanks.

enter image description here

+1
source share
3 answers

Got an answer, having tried a little.

First of all, I created a custom CPTLayer, and inside it was used the image that needs to be filled.

File CustomImageForScatterPlot.h

 #import "CPTLayer.h"


 @interface CustomImageForScatterPlot : CPTLayer
 {    
     UIImage *_image;

 }
 -(id)initWithImage:(UIImage *)image;

 @end

File CustomImageForScatterPlot.m

#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

, Scatter

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

....:)

+4

-symbolForScatterPlot:recordIndex: datasource . fill , .

+3

: , CPTPlotSpaceAnnotation CPTLayer, . - CPTPlotSymbol renderAsVectorInContext .

, .

+1

All Articles