CorePlot 1.5.1 中 plotAreaViewPointForPlotPoint 的用法

Usage for plotAreaViewPointForPlotPoint in CorePlot 1.5.1

我正在尝试使用 coreplot 1.5.1 和 swift 将 UIPopoverController 之类的东西添加到 barPlot 中。喜欢这个Core Plot: How to present popover from a bar selected by the user

所以我们需要知道所选柱线所在的点,但看起来有些函数是不同的,比如 plotAreaViewPointForPlotPoint。 1.5.1中有两个参数: 我试图找到正确的使用方法但失败了,这是我的代码:

func barPlot(plot: CPTBarPlot!, barWasSelectedAtRecordIndex idx: UInt, withEvent event: UIEvent!) {
    // Remove all the annotations
    graphView.hostedGraph.plotAreaFrame.plotArea.removeAllAnnotations()

    // Setup a style for the annotation
    let hitAnnotationTextStyle      = CPTMutableTextStyle.textStyle() as! CPTMutableTextStyle
    hitAnnotationTextStyle.color    = CPTColor.whiteColor()
    hitAnnotationTextStyle.fontSize = 12.0;
    hitAnnotationTextStyle.fontName = FONT_HEITI;


    // Determine point of symbol in plot coordinates
    let anchorPoint = [Int(idx),0]
    // Add annotation
    // First make a string for the y value
    let string = "\(idx),values is:\(mArray.objectAtIndex(Int(idx)))"
    // Now add the annotation to the plot area
    let textLayer = CPTTextLayer(text: string, style: hitAnnotationTextStyle)

    // popview, DxPopover is something like UIPopover Controller in iPhone
    var popView = DXPopover()
    annotationLabel.text = string

    var pointers = [NSDecimal](count: 2, repeatedValue: CPTDecimalFromUnsignedInteger(0))
    pointers[0] = CPTDecimalFromUnsignedInteger(idx)

    var plotPointer: UnsafeMutablePointer<NSDecimal> = UnsafeMutablePointer<NSDecimal>.alloc(pointers.count)
    plotPointer.initializeFrom(pointers)

    var popPoint  = graphView.hostedGraph.defaultPlotSpace.plotAreaViewPointForPlotPoint(plotPointer, numberOfCoordinates: idx)
    popView.showAtPoint(popPoint, popoverPostion: DXPopoverPosition.Down, withContentView: self.annotationView, inView: graphView)

    // selectedBarAnnotation = CPTPlotSpaceAnnotation(plotSpace: graphView.hostedGraph.defaultPlotSpace, anchorPlotPoint: anchorPoint)
    // selectedBarAnnotation!.contentLayer = textLayer
    // selectedBarAnnotation!.displacement = CGPointMake(0.0, -15.0)
    // graphView.hostedGraph.plotAreaFrame.plotArea.addAnnotation(selectedBarAnnotation)

}

它会在这条线处粉碎:

var popPoint  = graphView.hostedGraph.defaultPlotSpace.plotAreaViewPointForPlotPoint(plotPointer, numberOfCoordinates: idx)

那么,如何获得正确的 CGPOINT?

非常感谢!

=================编辑===================

我把我的代码改成这个,并且可以得到正确的点,感谢@Bannings

var popView = DXPopover()
    annotationLabel.text = string

    var pointers = [NSDecimal](count: 2, repeatedValue: CPTDecimalFromUnsignedInteger(0))
    let plotXvalue = self.numberForPlot(plot, field: UInt(CPTScatterPlotFieldX.value), recordIndex: idx)
    pointers[0] = CPTDecimalFromFloat(plotXvalue.floatValue)
    println("\(CPTDecimalFromUnsignedInteger(idx))")

    let plotspace = graphView.hostedGraph.defaultPlotSpace
    println("\(plotspace.numberOfCoordinates)")

    var popPoint  = plotspace.plotAreaViewPointForPlotPoint(&pointers, numberOfCoordinates: plotspace.numberOfCoordinates)
    popView.showAtPoint(popPoint, popoverPostion: DXPopoverPosition.Down, withContentView: self.annotationView, inView: graphView)

试试这个:

var popPoint  = graphView.hostedGraph.defaultPlotSpace.plotAreaViewPointForPlotPoint(&pointers, numberOfCoordinates: idx)