gpt4 book ai didi

iOS Core Plot with Swift - 格式化 Axis

转载 作者:行者123 更新时间:2023-11-29 01:38:51 24 4
gpt4 key购买 nike

嗨,我是核心情节的新手,我遇到了这个问题,并且它困扰了我一段时间。问题是 X Axis 和 Y Axis 都不会显示 Axis 标签、 Axis 瓦片、 Axis majorlengthinterval 等。基本上,除了轴线样式外,我无法设置 Axis 属性。以下是我的代码。

class testVC: UIViewController, CPTPlotDataSource, CPTPlotDelegate, CPTPlotSpaceDelegate {

var hostView: CPTGraphHostingView!

let xData = ["2","4"]
let yData = ["1","2"]

override func viewDidLoad() {
super.viewDidLoad()


}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()

}

func symbolForScatterPlot(aPlot: CPTScatterPlot, recordIndex index: UInt) -> CPTPlotSymbol {
let dotStyle = CPTPlotSymbol()
dotStyle.size = CGSizeMake(6, 6)
dotStyle.fill = CPTFill(color: CPTColor.blueColor())
dotStyle.symbolType = CPTPlotSymbolType.Ellipse
return dotStyle
}

@IBAction func plotClick(sender: AnyObject) {

let frame = self.view.frame
//add graph
let graph = CPTXYGraph(frame: CGRect(x: 0, y: 50, width: frame.width, height: frame.height - 250))
graph.paddingBottom = 10
graph.paddingLeft = 10
graph.paddingRight = 10
graph.paddingTop = 10
graph.title = "Scatter Plot"

//hostView
hostView = CPTGraphHostingView(frame: graph.frame)
self.view.addSubview(hostView)

//add scatter plot and plot space
var scatterPlot = CPTScatterPlot()
scatterPlot = CPTScatterPlot(frame: hostView.frame)
scatterPlot.delegate = self
scatterPlot.dataSource = self
let plotSpace = graph.defaultPlotSpace as! CPTXYPlotSpace
plotSpace.delegate = self
plotSpace.allowsUserInteraction = true
plotSpace.xRange = CPTPlotRange(location: 0, length: 10)
plotSpace.yRange = CPTPlotRange(location: 0, length: 18)

scatterPlot.dataLineStyle = nil //hide line

graph.addPlot(scatterPlot)

//set axis
let axes: CPTXYAxisSet = CPTXYAxisSet(layer: graph.axisSet!); let x = axes.xAxis; let y = axes.yAxis
let lineStyle = CPTMutableLineStyle()
lineStyle.lineWidth = 3
x!.axisLineStyle = lineStyle; y!.axisLineStyle = lineStyle
x!.title = "X"; y!.title = "Y"
x!.orthogonalPosition = 0; y!.orthogonalPosition = 0
x!.majorIntervalLength = 1; y!.majorIntervalLength = 1
x!.minorTickLength = 4; y!.minorTickLength = 4


hostView.hostedGraph = graph


}

func numberOfRecordsForPlot(plot: CPTPlot) -> UInt {
return 2
}

func numberForPlot(plot: CPTPlot, field fieldEnum: UInt, recordIndex idx: UInt) -> AnyObject? {
if fieldEnum == 0 {
return xData[Int(idx)]
} else {
return yData[Int(idx)]
}

}

最佳答案

您不是在属于图形的 Axis 属性上设置 Axis 属性——您是在设置一个副本,然后它就会消失。试试这个:

let axes = graph.axisSet as? CPTXYAxisSet

关于iOS Core Plot with Swift - 格式化 Axis ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32654037/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com