2

I am using iOS Charts with Swift 3.

When a user clicks on a circle/point on my graph, I want to show a popup that has the value and a date.

Graph

I detect the click inside chartValueSelected() and show the popup like this:

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

Right now I am just positioning the popup arbitrarily with frame because I don't know how to determine where the user clicked.

Is there a way to know the x/y coordinates of where the clicked circle is?

Clifton Labrum
  • 13,053
  • 9
  • 65
  • 128

1 Answers1

0

Ah, found it!

The hightlight value returned by the delegate method has xPx and yPx properties related to where the circle is. Wow, they really thought of everything with this graph library. :)

So I hard-coded a relative offset like this:

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

...and it works: enter image description here

Clifton Labrum
  • 13,053
  • 9
  • 65
  • 128