简体   繁体   English

使用CorePlot CPTAxisLabelingPolicyAutomatic设置显示最大y轴

[英]Showing max y-axis with CorePlot CPTAxisLabelingPolicyAutomatic setting

I want to plot a figure which have the max y axis value label showing on the label tick with CPTAxisLabelingPolicyAutomatic setting. 我想绘制一个图,其中使用CPTAxisLabelingPolicyAutomatic设置在标签刻度上显示了最大y轴值标签。 However I haven't found any public function allow me to do that. 但是我还没有发现任何公共功能允许我这样做。

After checking CorePlot source code (autoGenerateMajorTickLocations method) I think I can do some workaround by using CPTDecimalDivide and CPTNiceNum. 在检查CorePlot源代码(autoGenerateMajorTickLocations方法)之后,我认为我可以通过使用CPTDecimalDivide和CPTNiceNum做一些解决方法。 I implemented my code by increasing my plotRange in Y axis with the calculated "nice number" interval 我通过使用计算出的“ nice number”间隔增加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))

However the CPTNiceNum is not a public method so I am wondering are there any better way to do that? 但是,CPTNiceNum不是公共方法,所以我想知道还有更好的方法吗?

Call -layoutIfNeeded on the graph to make sure the axis labels are updated and then read the majorTickLocations set from the y-axis. 在图形上调用-layoutIfNeeded以确保更新了轴标签,然后从y轴读取majorTickLocations设置。 You can find the max location value in the set easily. 您可以在集合中轻松找到最大位置值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM