核心绘图x轴标签重叠/ CPTLabellingPolicyAutomatic将不会显示日期

时间:2012-02-22 02:12:22

标签: iphone ios core-plot

我在iPhone应用程序中有一个Core Plot图,并希望限制x轴上的标签数量。目前我正在使用CPTLabelingPolicyNone并在x轴上显示NSDates(显示如:1月2日)没有问题,除了一旦超过10个条目,它们开始相互重叠的事实。我真的希望在x轴上最多有7或8个条目。

我已经读过我可以使用CPTAxisLabelingPolicyAutomatic并将preferredNumberOfTicks设置为我想要的。问题是,当我这样做时,我不再在我的x轴上得到日期,我得到像0.1,0.1等十进制数字。我不是这方面的专家,所以我不确定为什么我我不再约会了。谁能对此有所了解?

感谢。

1 个答案:

答案 0 :(得分:1)

使用CPTTimeFormatter

NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
dateFormatter.dateStyle = kCFDateFormatterShortStyle;
CPTTimeFormatter *timeFormatter = [[[CPTTimeFormatter alloc] initWithDateFormatter:dateFormatter] autorelease];
timeFormatter.referenceDate = refDate;
axis.labelFormatter = timeFormatter;

一些Core Plot示例应用程序演示了此功能,包括Plot Gallery和DatePlot。