0
votes

There are quite a few questions here on SO on how to fix an axis in CorePlot but all of them reference the axisConstraints property of the CPTXYAxis which is nonexistent in CorePlot 2.0 and later.

So the question is how to fix the Y axis in core plot 2.0 and newer?

I'm not doing anything fancy here:

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
1

1 Answers

0
votes

The axisConstraints property is part of the CPTXYAxis class. Casting the axis set to CPTXYAxisSet is the easiest way to do this in Swift:

let axisSet = graph.axisSet as! CPTXYAxisSet
let y = axisSet.yAxis
y.axisConstraints = CPTConstraints(lowerOffset: 0.0)