如何使用Core Plot避免某个物理区域中的轴标签

时间:2013-04-16 09:38:36

标签: ios core-plot

我正在使用Core Plot绘制一段时间的图形,目前将x轴'labeledPolicy设置为CPTAxisLabelingPolicyAutomatic。但是,我想使用右下角绘制图像。所以我需要阻止绘图在该区域绘制标签。我想过使用labelExclusionRanges,但这需要从物理大小到时间值范围的映射。有没有更简单的方法来实现我的目标?

尝试将Eric的答案转换为代码可以获得一个图像,但它现在放在x轴的旁边,而我真的希望它位于x轴的右边标签。它也部分取决于图表的主机视图...

[更新:需要设置layer.frame以实际查看图像。]

- (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 个答案:

答案 0 :(得分:0)

制作CPTBorderedLayer并使用您的图片制作fill。使用此图层作为图层注释的内容图层,并将注释附加到所需位置的图形。

相关问题