0
votes

I'm using Core Plot to plot a graph over time, currently setting the x axis' labelingPolicy to CPTAxisLabelingPolicyAutomatic. However, I would like to use the lower right corner for drawing an image. So I need to prevent the plot from drawing labels in that area. I thought about using labelExclusionRanges, but that requires mapping from physical size to a time value range. Is there a simpler way to obtain my goal?

Attempting to translate Eric's answer into code gets me an image, but it's now placed next to the x axis, whereas I really want it to the right of the x axis labels. It's also partly off the graph's host view...

[UPDATE: Needed to set layer.frame to actually see the image.]

- (void)annotateXAxisOfGraph:(CPTGraph *)graph withImage:(CPTImage *)image
{
    CPTBorderedLayer *layer = [[[CPTBorderedLayer alloc] init] autorelease];
    layer.fill = [CPTFill fillWithImage:image];
    layer.frame = CGRectMake(0.0f, 0.0f, 40.0f, 40.0f);
    CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
    CPTLayerAnnotation *layerAnnotation = [[[CPTLayerAnnotation alloc] initWithAnchorLayer:axisSet.xAxis] autorelease];
    layerAnnotation.contentLayer = layer;
    layerAnnotation.rectAnchor = CPTRectAnchorBottomRight;
    [graph addAnnotation:layerAnnotation];
}
1

1 Answers

0
votes

Make a CPTBorderedLayer and use your image to make its fill. Use this layer as the content layer for a layer annotation and attach the annotation to the graph in the desired position.