Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

entriesForXValue() not finding point with matching xValue when it should #4668

Closed
darbysauter opened this issue Jun 22, 2021 · 5 comments
Closed

Comments

@darbysauter
Copy link

What did you do?

Tapped a point on my LineChart

What did you expect to happen?

Highlight a point

What happened instead?

Failed to highlight point

Charts Environment

Charts version/Branch/Commit Number:master
Xcode version:Latest
Swift version:Latest
Platform(s) running Charts:iPhoneX
macOS version running Xcode:BigSur

Demo Project

Unable to produce

Reason for this to happen

In entriesForXValue(_ xValue: Double) -> [ChartDataEntry] of ChartDataSet
it uses partitioningIndex() to find the first index that matches the xValue.

The xValue is from:
closest = set.entryForXValue(xValue, closestToY: .nan, rounding: rounding)

Which I have verified is working properly:
image

As you can see xValue matches the x value of the entry at index 3. using firstIndex() also produces index 3, but partitioningIndex() returns the the index after the last of entries.

So to debug this, after the case where it could not find the index I manually check every entry and Int round them, If I find a match I then test firstIndex() using the same predicate as partitioningIndex() (so no Int rounding), and this works.

partitioningIndex() does work sometimes but I couldn't figure out a common cause.

Assuming my assumption that partitioningIndex() and firstIndex() should do the same thing then partitioningIndex() is broken.

Any ideas how to properly fix this? for the meantime I may just use firstIndex() on my fork.

@ggorlim
Copy link

ggorlim commented Jun 30, 2021

I have same issue, so as workaround i rewrite method entriesForXValue, using code from older lib version:

override func entriesForXValue(_ xValue: Double) -> [ChartDataEntry]
{
var entries = ChartDataEntry
var low = startIndex
var high = endIndex - 1
while low <= high...

This work, but we have some other issues, i m not think they are related to this, like rendering only first from multiple graphs..

I think this issue also have same problem : #4645 Markers not appearing as expected

@lancelot9527
Copy link

I have same issue, so as workaround i rewrite method entriesForXValue, using code from older lib version:

override func entriesForXValue(_ xValue: Double) -> [ChartDataEntry]
{
var entries = ChartDataEntry
var low = startIndex
var high = endIndex - 1
while low <= high...

This work, but we have some other issues, i m not think they are related to this, like rendering only first from multiple graphs..

I think this issue also have same problem : #4645 Markers not appearing as expected

It work,thanks
I use 3.6.0 version fix this problem

@logancautrell
Copy link

logancautrell commented Sep 21, 2021

I can confirm that 3.6.0 fixes the selection issue. 4.0.1 version is busted.

drewster99 added a commit to drewster99/Charts that referenced this issue Oct 6, 2021
…ng xValue when it should" (ChartsOrg#4668).

Resolves Issue 4645 "Markers not appearing as expected" (ChartsOrg#4645).

The entriesForXValue function was incorrectly partiioning on ==, and also sometimes incorrectly returning an array of values that don't match at all.
The entryIndex function's switch statement assumes that the closest X value had already been found, which would often not be the case, since we are partitioning on >=.
@dudenamedjune
Copy link

dudenamedjune commented Apr 23, 2022

Have a fix open for this #4817
#4719 (comment)

@pmairoldi
Copy link
Collaborator

Closed by #4721

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants