-
-
Notifications
You must be signed in to change notification settings - Fork 6k
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
(v3.0 + Swift3.0)ChartView highlightValueWithX not working #1495
Comments
@PhilJay |
Both Android and iOS? |
Yeah... |
Hmmm... just looked through the code, this is a tricky one. For the case that we have multiple entries on the same x-position, it won't be possible to successfully highlight a certain entry without any specification of the y-position. So maybe we should drop this method? |
Well the problem starts with selection from touch events - it still does not really work, if you have a scatter or bubble charts with multiple values on same x. It actually selects the first or last one on the same x - depending on the position of the touch on the X axis! After we fix that - I guess out algorithm will know to take a Y value and after reaching the correct X it will start searching for the correct Y. |
Is there any current work around to programmatically highlight a line chart item? Are all the highlight methods broken at the moment? |
@apurva line chart should work just fine. I checked ChartsDemo with latest mater branch |
Programmatically highlight still not working in line charts. I try to highlight the last value:
But in delegate method - (void)chartValueSelected:entry:highlight: highlight.xPx and highlight.yPx are NaN. |
I can re-confirm that highlightValueWithX is not working. I tried creating a highlight Is there any way to create a ChartHighlight * object containing the y value as well? I see various init methods for the ChartHighlight class but all others need absolute pixel positions. @liuxuan30 Can you point out which part of the charts demo highlights a chart programmatically? Alternatively, is there a way to show the currently selected entry in any other mechanism besides using highlighting? This is absolutely essential for TVOS since Charts does not support the focus environment, and user interactions on the chart need to be handled programmatically instead of relying on the built in gesture recognizers. |
To work around this issue I've done the following in my local copy: In Highlight.swift, add an initializer that takes a y value as well: /// - parameter x: the x-value of the highlighted value
/// - parameter y: the y-value of the highlighted value
/// - parameter dataSetIndex: the index of the DataSet the highlighted value belongs to
public init(x: Double, y: Double, dataSetIndex: Int)
{
_x = x
_y = y
_dataSetIndex = dataSetIndex
} Then when I want to programmatically highlight, I do it like so: let entry = //... the ChartDataEntry I want to highlight
self.chart.highlightValue(
Highlight(x: entry.x, y: entry.y, dataSetIndex: 0)
) I'm definitely not familiar enough with the code to know if this is decent approach to move forward with or not. If it is, I think one thing that would help is a |
Actually, looking closer, I found that there were recent fixes to some of the other renderers that were not applied to Line charts. In this commit: 8905a46#diff-52d760df99fc778bb8222bd3cc9ce413R225 The I'll try that out and hopefully get a PR for it ready today time permitting. |
Also, it doesn't look like the y Value is actually used, since the highlight line just goes from contentTop to contentBottom. The root of the issue is actually that in this line: let pt = trans.pixelForValues(x: x, y: y) If
|
… used in `ScatterChartRenderer`. Fixes ChartsOrg#1495. I'm not sure if iterating over entries is necessary, or if this can be collapsed to just a single `set.entryForXValue()` call.
@apurva can you try my https://github.com/ryanschneider/Charts/tree/fix-1495 And see if it works as expected for you? It's working for me. @danielgindi & @liuxuan30, I more or less copied the code from I don't think I need to be iterating over It'd also be nice to add a programmatic highlight option to the ChartsDemo to aid in regression testing highlight bugs, but I haven't investigated what it'd take to do that. |
Thank you for your efforts @ryanschneider ! @danielgindi what you think? |
@ryanschneider Thanks for your efforts. I tried the changes in your branch, but both the methods highlightValueWithX and highlightValueWithHighlight both still do not work for me. The y value of the highlight is still NaN and the highlight does not draw on the chart when called programmatically. |
@danielgindi Just tested with the latest master, including your commit at 32a5952 highlightValueWithX still does not show the highlight lines. The delegate gets fired and the y value of highlight is still NaN in the delegate. As the case earlier, highlighting via the gesture recognizers show the highlight lines, only not so when highlightValueWithX is called. |
Still does not work. |
Still not working for me in Swift 3. `class ChartsViewController: UIViewController {
}` |
Change this line: lineChartView.highlightValue(x: 3, dataSetIndex: 0) to: lineChartView.highlightValue(Highlight(x: 3, y: 0, dataSetIndex: 0) |
I tried specifying a y:0 on a line graph with multiple datasets and it still doesn't work. Is there any update on this? It's a pretty big bug. I'm calling from Objective C. |
Little hack to get the position of the highlighted value
|
I tried your hack , jndefosse, but how can I call the function to show the labels only when entry is highlighted? |
Is this bug fixed? I cannot seem to highlight a section in Pie Chart s of iOS 13.5 Swift 5.1 |
Closed by #4721 |
ChartView highlightValueWithX method seems to stop working for v3.0 + Swift3.0
Xcode 8/Master branch/Objc.
The text was updated successfully, but these errors were encountered: