gpt4 book ai didi

cocoa - 条形图未与核心图的 CPTBarPlot 中的 X 轴刻度对齐

转载 作者:行者123 更新时间:2023-12-03 16:38:28 25 4
gpt4 key购买 nike

我在 Cocoa 上的 Core Plot 中遇到 CPTBarPlot 问题。也就是说,我无法控制条形的步长。 X 轴刻度通常设置为从 1 到无穷大的整数,并且可以在其上绘制散点图。

但是,当绘制条形图时,只有第一列在第一个刻度处开始(当然具有适当的偏移量)。第二个距离它的刻度稍远一些,第三个和所有其他的也是如此,如屏幕截图所示:

enter image description here

我还没有找到任何属性来控制它,但是,我发现了数据源方法

-(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];

我必须补充一点,当在同一绘图空间上绘制散点图并且它完美匹配时,会使用相同的刻度......

最佳答案

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,它还会询问每个柱的基值。

关于cocoa - 条形图未与核心图的 CPTBarPlot 中的 X 轴刻度对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8412613/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com