You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't see the line chart is wrong. if you are asking the sub view you manually created, that's because your axis coordinate system is not the same. ask this on stack overflow - as this is a UIKit or CoreGraphics topic. Apple has docs that explained pretty well.
short answer: you should use CoreGraphics to draw the shape you want. Not by a sub view. This library has some similar methods did so, like ChartMarker, drawHighlighted, you can refer those
The question was about the wrong coordinate values, when I’m adding circles for each entry and tap on one of the circles (that represents entry) I’m getting the right coordinates.
Maybe my question was unclear but I expected that the method ‘entryForIndex’ will return the same coordinate values like as I tapped on an entry.
Anyway, I managed to solve it in another way (tapping on entry to get the real coordinates as I described above and then adding a subview in the right position).
Hello!
I'm getting weird results while I'm trying to get pixel values for a specific entry that displayed on the chart view.
Convert entry to pixel:
let optionalEntry = dataSet.entryForIndex(13) // yValue = 0.69
guard let entry = optionalEntry else {continue}
let entryPixel = chartView.getTransformer(forAxis: .left).pixelForValues(x: entry.x, y: entry.y)
Draw the pixel on the chartView:
let view = UIView(frame: CGRect(x: entryPixel.x, y: entryPixel.y, width: 18, height: 18))
let circlePath = UIBezierPath(arcCenter: CGPoint(x: 9, y: 9), radius: CGFloat(4.5), startAngle: CGFloat(0), endAngle: CGFloat(Double.pi * 2), clockwise: true)
let shapeLayer = CAShapeLayer()
shapeLayer.path = circlePath.cgPath
shapeLayer.fillColor = UIColor.white.cgColor
shapeLayer.strokeColor = UIColor.blue.cgColor
shapeLayer.lineWidth = 3.0
view.layer.addSublayer(shapeLayer)
view.backgroundColor = UIColor.yellow
self.chartView.addSubview(view)
The subview is drawn in the wrong position:
Are there any ideas about what's wrong with the code?
The text was updated successfully, but these errors were encountered: