swift - iOS 图表 : Determine Circle Position on chartValueSelected()

标签 swift ios-charts nspopover

我正在使用 iOS Charts使用 Swift 3。

当用户点击我图表上的圆圈/点时,我想显示一个包含值和日期的弹出窗口。

Graph

我检测到 chartValueSelected() 中的点击并显示如下弹出窗口:

func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) {
  //Set and show the popup...
  //...
  self.presentViewController(vc, asPopoverRelativeTo: frame, of: graph, preferredEdge: .minY, behavior: .transient)
}

现在我只是用 frame 任意定位弹出窗口,因为我不知道如何确定用户点击的位置。

有没有办法知道点击圆圈所在位置的 x/y 坐标?

最佳答案

啊,找到了!

委托(delegate)方法返回的 hightlight 值具有与圆所在位置相关的 xPxyPx 属性。哇,他们真的用这个图形库想到了一切。 :)

所以我像这样硬编码了一个相对偏移量:

let frame = CGRect(x: highlight.xPx-36, y: highlight.yPx-15, width: 73, height: 54)

...它有效: enter image description here

关于swift - iOS 图表 : Determine Circle Position on chartValueSelected(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42034727/

相关文章:

iOS 以编程方式添加 UITableView 部分并重新加载它

swift - 将标签的位置更改为在数据集圆圈内

swift - NSPopover 解雇不会将其从 parent presentedViewController 中删除(代码 11)

objective-c - NSPopover 中的 NSOutlineView 在 OSX 10.10 Yosemite 中不可读

ios - 将音频转换为 [Double] 类型的原始 PCM 数据

ios - SKPhysicsBody 的 .dynamic 属性

xcode - 为什么 swift 中的 self 有时颜色不同?

iOS 图表 - 图表底部出现空白线

swift - 允许 PieChartView 在 Swift 中隐藏小切片的值线

macos - Touchbar 和 NSPoover 窗口