将图像剪辑到Core Plot CPT BarPlot中条形图条的边框

时间:2014-05-22 10:01:09

标签: ios core-plot bar-chart

在我的代码图像中使用CPTPlotSpaceAnnotaions代替数据标签,在条形图的每个条形图的中心显示。图像放置在中心并且工作正常,但如果图像被放大,则它会在条形图外伸展。我需要它来切断条宽。

使用

绘制图像
CPTBorderedLayer *borderedLayerObject =[[CPTBorderedLayer alloc] initWithFrame:CGRectMake(0, 0, 52, 52)];
borderedLayerObject.fill = [CPTFill fillWithImage:cptimage];

NSArray *anchorPoint = [NSArray arrayWithObjects:xPosition, yPosition, nil];
CPTPlotSpaceAnnotation *imageAnnotation = [[CPTPlotSpaceAnnotation alloc]initWithPlotSpace:graph.defaultPlotSpace anchorPlotPoint:anchorPoint];
imageAnnotation.contentLayer = borderedLayerObject;
[graph.plotAreaFrame addAnnotation:imageAnnotation];
return imageAnnotation;

并将此borderedLayerObject设置为CPTPlotSpaceAnnotation的contentLayer,并返回CPTPlotSpaceAnnotation对象...

我绘制的图像采用了borderedLayerObject的帧大小,并将其放置在条形图中的条形图上,所以我无法理解如何裁剪我绘制的图像......

使用CPTPlotSpaceAnnotation我需要在条形图的中心显示图像,使用锚点我已经给出了必须在条形图条中显示图像的x和y位置。请帮我解决问题......

1 个答案:

答案 0 :(得分:0)

很容易确定条的宽度。如果barWidthsAreInViewCoordinatesYES,则宽度由barWidth属性给出。否则,您必须使用绘图空间将数据坐标转换为像素。沿着垂直于条形的轴(例如,垂直条的x轴)选择两个barWidth单位的点,将它们转换为视图坐标与绘图空间,并从中找到宽度转换点。