我在Cocoa上的Core Plot中遇到了CPTBarPlot的问题。也就是说,我无法实现控制条的步幅宽度。X轴刻度通常设置为从1到无穷大的整数,并在其上绘制散点图。
但是,当绘制条形图时,只有第一列从第一个刻度开始(当然,带有适当的偏移)。Second离它的刻度稍远一点,third和所有其他的也是如此,如截图所示:

我还没有找到任何属性来控制这一点,但是我发现了数据源方法
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index与绘制散点图时的行为不同。也就是说,它只枚举整数3,它是CPTBarPlotBindingBarTips,不枚举任何其他常量,我特别担心缺少CPTBarPlotBindingBarLocations。
如果我从Plot Gallery mac演示项目启动VerticalBarChart,我会检查并看到相同方法以相同的顺序枚举3,4和2个常量。
我使用的是Core Plot 0.9,我相信在这个演示中是一样的。不过..。
如何解决这个问题?
下面是X轴上的标签和刻度的完整代码;
x.labelRotation = M_PI/4;
x.labelingPolicy = CPTAxisLabelingPolicyNone;
x.labelOffset = 0.0;
CPTMutableTextStyle *labelStyle = [CPTMutableTextStyle textStyle];
labelStyle.fontSize = 9.0;
x.labelTextStyle = labelStyle;
// NSMutableArray *dateArray = [dataSeries objectAtIndex:0];
NSMutableArray *customTickLocations = [NSMutableArray array];
NSMutableArray *xAxisLabels = [NSMutableArray array];
for (int i=0;i<[dataSeries count];i++) {
[customTickLocations addObject:[NSDecimalNumber numberWithInt:i+1]];
[xAxisLabels addObject:[dataSeries objectAtIndex:i]];
}
// [customTickLocations addObject:[NSDecimalNumber numberWithInt:[dateArray count]]];
NSUInteger labelLocation = 0;
NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:[xAxisLabels count]];
for (NSNumber *tickLocation in customTickLocations) {
CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText: [xAxisLabels objectAtIndex:labelLocation++] textStyle:x.labelTextStyle];
newLabel.tickLocation = [tickLocation decimalValue];
newLabel.offset = x.labelOffset + x.majorTickLength;
newLabel.rotation = M_PI/4;
[customLabels addObject:newLabel];
[newLabel release];
}
[x setMajorTickLocations:[NSSet setWithArray:customTickLocations]];
x.axisLabels = [NSSet setWithArray:customLabels];我必须补充的是,当散点图在相同的绘图空间上绘制并且完全匹配时,使用的是相同的刻度。
发布于 2011-12-08 11:15:50
field参数将是此枚举的成员之一:
typedef enum _CPTBarPlotField {
CPTBarPlotFieldBarLocation = 2, ///< Bar location on independent coordinate axis.
CPTBarPlotFieldBarTip = 3, ///< Bar tip value.
CPTBarPlotFieldBarBase = 4 ///< Bar base (used only if barBasesVary is YES).
} CPTBarPlotField;如果绘图的plotRange属性为nil (默认值),则绘图将向数据源询问每个条形图的位置和提示。如果barBasesVary ==为YES,它还将询问每个条形图的基值。
https://stackoverflow.com/questions/8412613
复制相似问题