2015-06-26 34 views
0

我試圖在coreplot 1.5.1和swift中添加類似UIPopoverController的東西到barPlot中。像這樣一個Core Plot: How to present popover from a bar selected by the user在CorePlot 1.5.1中plotAreaViewPointForPlotPoint的用法

所以我們需要知道點的地方,但看起來像一些功能是不同的,如plotAreaViewPointForPlotPoint。在1.5.1中,有兩個參數: enter image description here 而我試圖找到使用它的正確方法,但失敗了,這裏是我的代碼:

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) 

回答

0

試試這個:

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