I have a line limit with a label. I would like to replace that label with an image. I realize the ios-charts library can't do that directly but was looking for some insight on how to do this.
Asked
Active
Viewed 808 times
2
-
Sounds something that could be easy to implement with SwiftCharts https://github.com/i-schuetz/SwiftCharts - it's done specially for this kind of this - custom overlays, etc. – User Jul 19 '15 at 17:41
1 Answers
0
There are several ways to do so:
Add the image outside of the ios-charts system, you can calculate the position of the image, and add it there;
You can subclass the ChartLimitLine, add a new property called UIImage, and then you can use it. You may subclass the chart view as a child chart view, and you can add your child limit line there, and then add the image to the view.
If the image is not complicated, such as simple lines and dots, you can choose to manually draw the shape using CoreGrahpics.
It's quite flexible for you to choose a proper way to do that. Just remeber you only need the origin point and the size, then you can add your image wherever you want.
Doing customization requires you understanding OOP and ios-charts in depth.

Wingzero
- 9,644
- 10
- 39
- 80
-
Hi, I just stumbled upon the same problem. I am wondering what would be the best way to calculate what is the Y position of the ChartLimitLine, so I can adapt the position of my image view? – Georgi Mar 09 '16 at 10:40
-
-
-
-
-
Thanks, it worked fine in the end. Initially I was getting a wrong value from `getPixelForValue` because I was setting up the chart in `viewDidLoad`. After moving the code to `viewWillAppear` it works as expected. – Georgi Mar 09 '16 at 16:00