Reputation: 6475
I was looking everywhere for this and wasn't able to find any solution or any hint on how to achieve this. I want to draw an indicator (circle) only for selected/highlighted point. Right now I have
dataSet.drawCircleHoleEnabled = false
dataSet.drawCirclesEnabled = false
So my line chart looks simple, but as soon as I start dragging my finder and seeing highlight indicator, I also want to see a circle showing me the data entry. I want something which looks like this:
So far the only thing coming to my mind was creating another data set and configure it on the fly using delegates, but it seems like overkill for something so common.
Upvotes: 1
Views: 1741
Reputation: 2922
you need to create a Custom Marker
class CircleMarker: MarkerImage {
@objc var color: UIColor
@objc var radius: CGFloat = 4
@objc public init(color: UIColor) {
self.color = color
super.init()
}
override func draw(context: CGContext, point: CGPoint) {
let circleRect = CGRect(x: point.x - radius, y: point.y - radius, width: radius * 2, height: radius * 2)
context.setFillColor(color.cgColor)
context.fillEllipse(in: circleRect)
context.restoreGState()
}
}
and use it
let marker = CircleMarker(color: .red)
chart.marker = marker
based on BallonMarker
Upvotes: 10