5

I'm using a custom image symbol, as described in Showing images on Scattering Graph as plot symbols in Core plot iOS. Also refer to Positioning label on CPTBarPlot (Core-Plot) regarding positioning of the data label in a CPTPlot.

However, I'm not seeing the behavior from CPTScatterPlot.labelOffset that I need. Positive values increase the distance between the image bottom and the point, while negative values increase the distance between the image top and the point. I need to center the image on the point. See screenshots:

  • positive labelOffset values: https://i.stack.imgur.com/O1uSe.png
  • negative labelOffset values: https://i.stack.imgur.com/E9fkL.png

My solution is hacky and requires me to modify the image frame in my CustomImageForScatterPlot's drawInContext method. Any ideas on how to make labelOffset work how I want?

Community
  • 1
  • 1
danhbear
  • 103
  • 1
  • 7

1 Answers1

5

That behavior is correct for data labels. You want to use a plot symbol.

-(CPTPlotSymbol *)symbolForScatterPlot:(CPTScatterPlot *)plot
                           recordIndex:(NSUInteger)index
{
    CPTPlotSymbol *symbol = nil;

    if ( /* use symbol for this index? */ ) {
        symbol = [CPTPlotSymbol ellipsePlotSymbol];
        symbol.fill = [CPTFill fillWithImage:/* symbol image */];
        symbol.size = CGSizeMake(width, height);
    }

    return symbol;
}

If you want every point to have a symbol, set the plotSymbol property instead of implementing this datasource method.

Eric Skroch
  • 27,381
  • 3
  • 29
  • 36
  • 3
    Thanks, you're right I was previously using `dataLabelForPlot`. FYI for others, the symbol image in the code sample above can reference a PNG resource using: `[CPTImage imageForPNGFile:[[NSBundle mainBundle] pathForResource:@"icon_volume" ofType:@"png"]]`. – danhbear Feb 04 '13 at 19:02
  • 1
    Except when you use the asset catalog :P http://stackoverflow.com/questions/20485453/creating-cptimages-from-images-in-xcassets-file – Sam Jarman Dec 10 '13 at 04:14