我想为y轴而不是数字设置字符串。我找到了这个帖子,
iOS Core Plot CPTAxisLabel alignment to CPTPlot
我试图将相应版本的代码实现到我的y轴,但没有成功。
是否可以在y轴上使用字符串而不是数字?
答案 0 :(得分:0)
找到解决方案。我必须将labeledPolicy设置为none(我的代码中的第2行),
CPTXYAxis *y = axisSet.yAxis;
y.labelingPolicy = CPTAxisLabelingPolicyNone;
CPTMutableTextStyle *style = [CPTMutableTextStyle textStyle];
style.color = [[CPTColor blackColor] colorWithAlphaComponent:1];
style.fontName = @"Helvetica-Bold";
style.fontSize = 10.0f;
NSMutableArray *test = [[NSMutableArray alloc] initWithObjects:@"Zero", @"One", @"Two", @"Three", @"Four", nil];
NSMutableArray *labels = [[NSMutableArray alloc] initWithCapacity:4];
int index = 0;
for (NSString *string in test)
{
CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:string textStyle:style];
label.tickLocation = CPTDecimalFromInt(index);
label.offset = 5.0f;
[labels addObject:label];
index++;
}
axisSet.yAxis.axisLabels = [NSSet setWithArray:labels];