IOS-Charts is by far the best chart drawing framework I've used to date (I've only used PNChart so far so that's not saying too much). Out of the box you get custom animations, touch events, and fill effects. It's enough to make a developer swoon.
That said iOS-Charts and I had a little trouble getting to know one another. The entire documentation is written for android developers in Java. Luckily, I had switched to Swift from Objective-C earlier that week, so reading the docs was super easy. That is, until I got to my floating graph reader...
You see that nice 3.0 with impressions and a date attached to it? Well it slides with your finger over the graph and changes it's values accordingly. Really, not a hard thing to implement if your graph has good docs. Unfortunately, mine didn't.
So if you want to create something similar, here are the steps to do it:
- In the file you are implementing the graph, be sure to include ChartViewDelegate
- Then implement the chartValueSelected method.
- If you then use the getMarkerPosition method, you'll be able to center your "marker" wherever you want.
Here's some sample code:
markerView is simply the UIView that contains three labels. It's the 3.0, impressions, and Apr you see in the picture. This acts as my "floating graph reader" for the graph.
The markerPosition is simply a CGPoint so you can use the x and y values to reposition your floating graph reader. Hopefully, this saves you the hours I spent looking for the getMarkerPosition method. I honestly had to scroll through all the methods of a chartView to find it, because (as I said before) iOS-Charts lacks documentation.