Core Plot 2.1 固定 Y 轴
Core Plot 2.1 fixed Y axis
这里有很多关于如何在 CorePlot 中修复轴的问题,但所有问题都引用了 CPTXYAxis
的 axisConstraints
属性,这在 CorePlot 中是不存在的2.0 及更高版本。
所以问题是如何在 core plot 2.0 及更新版本中修复 Y 轴?
我没有做任何花哨的事情:
let graph = CPTXYGraph(frame: self.nativeView.graphView.bounds)
let plotSpace = graph.defaultPlotSpace!
plotSpace.setPlotRange(CPTPlotRange(location: -1, length: 20), forCoordinate: .X)
plotSpace.setPlotRange(CPTPlotRange(location: -10, length: 20), forCoordinate: .Y)
plotSpace.allowsUserInteraction = true
plotSpace.delegate = self
let axisSet = graph.axisSet
if let axis = axisSet?.axisForCoordinate(.Y, atIndex: 0) {
axis.majorIntervalLength = 5
axis.minorTicksPerInterval = 5
let formatter = NSNumberFormatter()
formatter.positiveFormat = "#"
formatter.negativeFormat = "#"
axis.labelFormatter = formatter
//Here I want to fix this thing..
}
//And then I create a scatter plot and add it and that's it
axisConstraints
属性 是 CPTXYAxis
class 的一部分。将轴设置为 CPTXYAxisSet
是在 Swift 中执行此操作的最简单方法:
let axisSet = graph.axisSet as! CPTXYAxisSet
let y = axisSet.yAxis
y.axisConstraints = CPTConstraints(lowerOffset: 0.0)
这里有很多关于如何在 CorePlot 中修复轴的问题,但所有问题都引用了 CPTXYAxis
的 axisConstraints
属性,这在 CorePlot 中是不存在的2.0 及更高版本。
所以问题是如何在 core plot 2.0 及更新版本中修复 Y 轴?
我没有做任何花哨的事情:
let graph = CPTXYGraph(frame: self.nativeView.graphView.bounds)
let plotSpace = graph.defaultPlotSpace!
plotSpace.setPlotRange(CPTPlotRange(location: -1, length: 20), forCoordinate: .X)
plotSpace.setPlotRange(CPTPlotRange(location: -10, length: 20), forCoordinate: .Y)
plotSpace.allowsUserInteraction = true
plotSpace.delegate = self
let axisSet = graph.axisSet
if let axis = axisSet?.axisForCoordinate(.Y, atIndex: 0) {
axis.majorIntervalLength = 5
axis.minorTicksPerInterval = 5
let formatter = NSNumberFormatter()
formatter.positiveFormat = "#"
formatter.negativeFormat = "#"
axis.labelFormatter = formatter
//Here I want to fix this thing..
}
//And then I create a scatter plot and add it and that's it
axisConstraints
属性 是 CPTXYAxis
class 的一部分。将轴设置为 CPTXYAxisSet
是在 Swift 中执行此操作的最简单方法:
let axisSet = graph.axisSet as! CPTXYAxisSet
let y = axisSet.yAxis
y.axisConstraints = CPTConstraints(lowerOffset: 0.0)