核心图 CPTAxisLabelingPolicyAutomatic 仅限天数

Core Plot CPTAxisLabelingPolicyAutomatic Days only

我在 x 轴上使用 CPTAxisLabelingPolicyAutomatic 作为一年中几天的时间线(例如 2015 年 3 月 7 日)。

这是我的参考日期:

let components = NSDateComponents()
components.month = 10
components.day = 29
components.year = 1970
components.hour = 0
components.minute = 0
components.second = 0
referenceDate = NSCalendar.currentCalendar().dateFromComponents(components)!

这是我的 x 轴样式的一部分

x.labelingPolicy = .Automatic
let oneDay:NSTimeInterval = 60 * 60 * 24
x.majorIntervalLength = oneDay
x.minorTicksPerInterval = 0

let formatter = NSDateFormatter()
formatter.dateStyle = .MediumStyle
formatter.timeStyle = .NoStyle

let timeFormatter = CPTTimeFormatter(dateFormatter: formatter)
timeFormatter.referenceDate = referenceDate
x.labelFormatter = timeFormatter

尽管如此,问题是,x 值在 00:00:00 天的 NSDate 中不符合该特定日期的网格线:

但如果我使用 .FixedInterval 策略,我会得到正确的行为,但我会在捏合时松开自动标记。

我怎样才能从两个世界中获益?

自动标记算法不知道日期,因此它不会将轴拆分为 "nice" 日期间隔,例如天或周。目前,固定间隔标记策略是最好的解决方案。您可以根据显示的范围来确定合适的间隔。有一个 open issue 添加适当的日期支持,但它的优先级很低,我不能保证它什么时候完成。