【发布时间】:2011-12-07 08:58:37
【问题描述】:
我在 Cocoa 的 Core Plot 中遇到 CPTBarPlot 的问题。 即,我无法控制条的步宽。 X 轴刻度通常设置为从 1 到无限的整数,并且可以在其上绘制散点图。
但是,当绘制条形图时,只有第一列开始(当然,具有适当的偏移量)在第一个刻度上。第二个比它的刻度更进一步,第三个和所有其他的也是如此,如屏幕截图所示:
我还没有找到任何属性来控制这个,但是,我找到了数据源方法
-(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];
我必须补充一点,当在同一绘图空间上绘制散点图并且它完全匹配时,使用了相同的刻度......
【问题讨论】: