2016-05-22 6 views
0

Es gibt einige Fragen zu SO, wie man eine Achse in CorePlot repariert, aber alle verweisen auf die axisConstraints Eigenschaft von CPTXYAxis, die in CorePlot 2.0 und höher nicht existiert.Core Plot 2.1 feste Y-Achse

Die Frage ist also, wie die Y-Achse in Core-Plot 2.0 und neuer zu beheben?

Ich mache nichts Phantasie hier:

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 

Antwort

0

Die axisConstraints Eigenschaft Teil der CPTXYAxis Klasse. Gießen die Achse auf CPTXYAxisSet ist der einfachste Weg, dies in Swift zu tun:

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

Heiliger jesus ... das Problem war ich Gieße es nicht zu 'CPTXYAxisSet' so war es nur' CPTAxisSet' ... Ich fühle mich so dumm jetzt. Vielen Dank. – Majster

Verwandte Themen