我正在尝试使用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)

关于ios - CorePlot 1.5.1中plotAreaViewPointForPlotPoint的用法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31064418/

10-10 20:35