核心图:x 轴标记为年度季度
我有一些图,其中 x 轴定义为年度季度数,如下所示:
1978.1 1978.2 1978.3 1978.4 1979.1 1979.2 是
我只想将季度日期数组 (NSMutableArray * yyyyQ) 的对象编号映射到 x 轴上的点 0、1、2、3 等。换句话说,0 是 1978.1,1 1978.2,2 是 1978.3 等。看起来是一个简单的任务,但使用自定义标签似乎有点矫枉过正,而 NSDateFormatter 似乎并不适合年度季度,因为季度的长度各不相同(有或没有闰年)。
按照我简单的方法,答案是这样的:
x.labelTextStyle = axisTitleTextStyle;
x.labelRotation = M_PI/2;
x.axisLabels = [NSSet setWithArray:yyyyQ];
I have plots where the x-axis is defined as a number of yearly quarters as follows:
1978.1
1978.2
1978.3
1978.4
1979.1
1979.2
etc
I just want to map the object numbers of an array of quarterly dates (NSMutableArray * yyyyQ) to the points along the x-axis that are 0, 1, 2, 3, etc. In other words, 0 is 1978.1, 1 is 1978.2, 2 is 1978.3, etc. Seems like a simple task, but using custom labels seems like overkill and NSDateFormatter doesn't seem suited to yearly quarters because the length of quarters varies (with or without a leap year).
In my simple-minded approach, the answer would be something like this:
x.labelTextStyle = axisTitleTextStyle;
x.labelRotation = M_PI/2;
x.axisLabels = [NSSet setWithArray:yyyyQ];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要创建一个自定义数字格式化程序来执行此操作。查看
CPTTimeFormatter
的源代码以了解所需的基本结构。您需要编写一个-stringForObjectValue:
方法来将编码数字转换为所需的格式。You'll need to create a custom number formatter to do that. Look at the source code for
CPTTimeFormatter
to see the basic structure needed. You'll need to write a-stringForObjectValue:
method that converts your coded numbers into the desired format.