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

Bug: Unsupported Operation (NaN) with nullSpots in fl_chart LineChart #1851

Open
gouthamrg opened this issue Jan 24, 2025 · 0 comments
Open

Comments

@gouthamrg
Copy link

When using nullSpots in fl_chart's LineChart to split the line, the app crashes with a NaN exception during layout. This seems to be caused by a calculation error when handling null values in spots. Below is the full stack trace and relevant code.

Steps to Reproduce:
Use LineChart from fl_chart.
Set up the LineChartBarData with nullSpots to split the line into multiple segments.
Run the app and trigger the chart rendering.
Observe the crash and NaN exception.

Expected Behavior:
The nullSpots feature should split the lines without causing a crash. It should gracefully handle null values and render the chart properly.

StackTrace

object.dart:2627
packages/flutter/src/rendering/proxy_box.dart 117:21                                    <fn>
proxy_box.dart:117
packages/flutter/src/rendering/object.dart 2627:7                                       layout
object.dart:2627
packages/flutter/src/rendering/proxy_box.dart 117:21                                    <fn>
proxy_box.dart:117
packages/flutter/src/rendering/object.dart 2627:7                                       layout
object.dart:2627
packages/flutter/src/rendering/proxy_box.dart 117:21                                    <fn>
proxy_box.dart:117
packages/flutter/src/rendering/object.dart 2627:7                                       layout
object.dart:2627
packages/flutter/src/rendering/proxy_box.dart 586:12                                    performLayout
proxy_box.dart:586
packages/flutter/src/rendering/object.dart 2627:7                                       layout
object.dart:2627
packages/flutter/src/rendering/proxy_box.dart 297:7                                     performLayout
proxy_box.dart:297
packages/flutter/src/rendering/object.dart 2627:7                                       layout
object.dart:2627
packages/flutter/src/rendering/layout_helper.dart 61:10                                 layoutChild
layout_helper.dart:61
packages/flutter/src/rendering/flex.dart 1079:71                                        [_computeSizes]
flex.dart:1079
packages/flutter/src/rendering/flex.dart 1121:32                                        performLayout
flex.dart:1121
packages/flutter/src/rendering/object.dart 2465:7                                       [_layoutWithoutResize]
object.dart:2465
packages/flutter/src/rendering/object.dart 1062:17                                      flushLayout
object.dart:1062
packages/flutter/src/rendering/object.dart 1075:14                                      flushLayout
object.dart:1075
packages/flutter/src/rendering/binding.dart 609:5                                       drawFrame
binding.dart:609
packages/flutter/src/widgets/binding.dart 1178:13                                       drawFrame
binding.dart:1178
packages/flutter/src/rendering/binding.dart 475:5                                       [_handlePersistentFrameCallback]
binding.dart:475
packages/flutter/src/scheduler/binding.dart 1397:7                                      [_invokeFrameCallback]
binding.dart:1397
packages/flutter/src/scheduler/binding.dart 1318:9                                      handleDrawFrame
binding.dart:1318
packages/flutter/src/scheduler/binding.dart 1176:5                                      [_handleDrawFrame]
binding.dart:1176
dart-sdk/lib/async/zone.dart 1414:13                                                    _rootRun
zone.dart:1414
dart-sdk/lib/async/zone.dart 1317:19                                                    run
zone.dart:1317
dart-sdk/lib/async/zone.dart 1225:7                                                     runGuarded
zone.dart:1225
lib/_engine/engine/platform_dispatcher.dart 1410:9                                      invoke
platform_dispatcher.dart:1410
lib/_engine/engine/platform_dispatcher.dart 310:5                                       invokeOnDrawFrame
platform_dispatcher.dart:310
lib/_engine/engine/initialization.dart 187:36                                           <fn>
initialization.dart:187
dart-sdk/lib/_internal/js_dev_runtime/patch/js_allow_interop_patch.dart 212:27          _callDartFunctionFast1
js_allow_interop_patch.dart:212

════════════════════════════════════════════════════════════════════════════════════════════════════
18
Another exception was thrown: Unsupported operation: NaN```

**Screenshot**

![Image](https://github.com/user-attachments/assets/e53564ac-659e-440d-a50d-d4be21e3aac8)

**Additional Context:**
The issue occurs when attempting to use nullSpots for splitting lines in the chart. It seems the library doesn't properly handle null values in the FlSpot list. Adding validation or better handling of null values might fix the issue.


Thanks in Advance!
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

1 participant