-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Line Chart tooltip on only certain lines #1620
Comments
The point is that we have a callback inside LineTouchData called // Default distanceCalculator only considers distance on x axis
double _xDistance(Offset touchPoint, Offset spotPixelCoordinates) {
return (touchPoint.dx - spotPixelCoordinates.dx).abs();
} But you can override it to consider both x and y axes. distanceCalculator:
(Offset touchPoint, Offset spotPixelCoordinates) =>
(touchPoint - spotPixelCoordinates).distance, I just updated the LineChartSample6. Please take a look: Screen.Recording.2024-05-09.at.02.20.22.mov |
Hey @imaNNeo thanks for the response. I am aware of the In my use case, there are two or more lines which may be arbitrarily close to or far from each other. It could be that for a given X value, the two lines even share the same Y value. Furthermore, I want the tooltip to be displayed for line 1 regardless of how far in the Y direction the mouse is from line 1, and I dont want the tooltip for line 2 regardless of how close in the Y direction the mouse is. The problem arises when Line 2 is far from Line 1 in the Y dimension. The tooltip is displayed above Line 2, instead of above Line 1 as desired. |
For this use-case, you can disable the builtInTouches and implement your own logic. have you tried that? |
I haven't. I actually assumed that if you set If I get some time to work on this, I'll give it a shot and report back. Thanks |
If you set In line chart sample 5, we have a custom implementation that might help. |
Great, thank you!
…On Wed, May 8, 2024 at 9:11 PM Iman Khoshabi ***@***.***> wrote:
If you set handleBuiltInTouches: false, it disables the default behavior,
so it's ready to implement your own logic.
It's simple, you override the touchCallback and you do whatever you want.
In line chart sample 5
<https://github.com/imaNNeo/fl_chart/blob/main/example/lib/presentation/samples/line/line_chart_sample5.dart>,
we have a custom implementation that might help.
—
Reply to this email directly, view it on GitHub
<#1620 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAYWQSAVJGFHLJ5VXZDRGF3ZBLELZAVCNFSM6AAAAABFNLSFGKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBRG42DMNBWHA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Is your feature request related to a problem? Please describe.
I have a line chart with multiple lines. I only want tooltips for a certain subset of the lines. I am aware of #1092, which shows how to hide the value for certain lines. However, there is still a problem. With that solution, the tooltip is displayed above the top-most line, regardless of whether that line has a tooltip.
Consider the following example:
Notice that the tooltip is displayed at the very top of the chart, but it pertains to the line at the very bottom.
Screen.Recording.2024-03-28.at.3.27.06.PM.mov
Describe the solution you'd like
Ideally in my example, the tooltip box should be adjacent to the bottom line, or say, adjacent to the top-most of the lines for which tooltip is non-null.
More generally, I would like an option to avoid showing tooltips for a certain line altogether. This option could be available on the
LineChartBarData
itself, for examplebool showTooltips
. If false, do not show any tooltips for this line, and do not consider this line when determining where to place the tooltip box.Describe alternatives you've considered
I am not aware of any other way to control where the tooltip box is positioned.
Additional context
Add any other context or screenshots about the feature request here.
The text was updated successfully, but these errors were encountered: