【发布时间】:2018-09-18 09:57:25
【问题描述】:
我想用 CPTAxisLabelingPolicyAutomatic 设置绘制一个在标签刻度上显示最大 y 轴值标签的图形。但是我还没有发现任何公共功能允许我这样做。
在检查 CorePlot 源代码(autoGenerateMajorTickLocations 方法)后,我想我可以通过使用 CPTDecimalDivide 和 CPTNiceNum 来解决一些问题。我通过使用计算出的“好数字”间隔增加 Y 轴上的 plotRange 来实现我的代码
var majorInterval = CPTDecimalDivide( Decimal(yAxisLength),
CPTDecimalFromUnsignedInteger(5-1))
majorInterval = CPTNiceNum(majorInterval)
let interval = Int(truncating: majorInterval as NSNumber)
let number = Int(yAxisLength/interval) + 1
yAxisLength = Int(Double(number * interval))
但是 CPTNiceNum 不是公共方法,所以我想知道有没有更好的方法来做到这一点?
【问题讨论】: