当使用CPTScatterPlot时,我可以调用plotAreaPointOfVisiblePointAtIndex,这给出了图形上特定索引所在位置的NSPoint。
我一直在试图弄清楚是否可以做一些类似的事情来获得CPTBarPlot的数据点的面积(x、y、宽度和高度),但到目前为止,我还没有弄清楚。
有人知道我能拿到吗?
发布于 2014-01-30 15:15:44
基于@ErikSkroch的详细信息,这是我想出的解决方案(当我结束使用私有方法而不是重写数学时有点烦躁)。
// Access to private methods
@interface CPTBarPlot()
-(CGFloat)lengthInView:(NSDecimal)decimalLength;
-(BOOL)barAtRecordIndex:(NSUInteger)idx basePoint:(CGPoint *)basePoint tipPoint:(CGPoint *)tipPoint;
@end
NSPoint basePoint, tipPoint;
if(![barPlot barAtRecordIndex: index
basePoint: &basePoint
tipPoint: &tipPoint]) return;
float width = [barPlot lengthInView: barPlot.barWidth];发布于 2014-01-30 02:06:54
如果您已经知道数据索引,则可以从数据源(或它使用的模型数据)中获取位置、基值和提示值。如果您正在使用barOffset,请使用它来调整条形图的位置。使用绘图空间将数据坐标转换为条形图末端的区域像素坐标。如果barWidthsAreInViewCoordinates为YES,则可以使用barWidth作为条形矩形的像素宽度。如果是NO,在转换为绘图区域坐标之前,您需要做一些数学来抵消条形图的角。如果您需要帮助进行计算,可以查看 implementation。
https://stackoverflow.com/questions/21441877
复制相似问题