0

With the new 4.0 update in iOS Charts, I have redone all of my charts, including changing a lot of them to CombinedChartViews. however, now I am running into a very weird issue with accessing the entries using the in-built functions.

The data is presenting fine, as expected, but when highlighting, only some of the values are selecting. These are the same values that are only accessible through functions such as getEntryByTouchPoint.

guard let valOrig = self.getEntryByTouchPoint(point: location) else { return }
guard let val = lineBaseSet?.entries.getItemAt(Int(valOrig.x)) else { return }
print(val.x)

Only works for 40, 60, etc.

When I print lineData.first.entries, I get the correct count of 79 and all the entries are correct and in order. It's just when I am not accessing the array directly it can't seem to find most of the entries.

Entries working perfectly = 40, 60, 70, 75, 78, 79.

All others are not working.

This order of numbers seems to be exponential but I still don't see how this relates to the way it's not working.

I have only tested this on a CombinedChartView so not sure if it's working on other types.

Any help would be appreciated!!

EDIT: Sorry, bit of context, location is the location of a touch point, lineBaseSet is a custom variable equal to lineData?.first, and getItemAt() is the same as array[index] but it returns an optional as opposed to fatally crashing if out of index.

1 Answer 1

0

Ok, this isn't a direct answer to the question but I've figured out a workaround for other people having the same issue.

The functions 'valueForTouchPoint(point:axis:)' and 'getPosition(entry:axis:)' still work as expected so using the following, the entry and location of the entry can be found from the response of a UIPanGestureRecognizer:

let touchPoint = sender.location(ofTouch: 0, in: chartView)
let point = chartView.valueForTouchPoint(point: touchPoint, axis: .left)
selectedEntry = entries.first(where: { $0.x == round(Double(point.x)) })
chartView.getPosition(entry: selectedEntry, axis: .left)

From there, it's possible to create the horizontal and vertical lines using a CAShapeLayer and adding that as a sublayer to the chartView.

Hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.