Closed becjit closed 2 weeks ago
Hi @becjit,
We can reproduce the reported exception when all data points are identical, and the axisCrossesAt value is set to the maximum data point. We have logged a bug report for this in our feedback portal, and the issue is scheduled to be fixed in our weekly release which is expected to be rolled out on August 20, 2024. We will notify you once the release is rolled out and appreciate your patience until then. You can also track the status of this bug using the feedback link below.
Feedback Link: https://www.syncfusion.com/feedback/60198/exception-thrown-when-axiscrossesat-equals-maximum-data-value-in-sparkline-chart
Regards,
Preethika Selvam.
Hi @becjit,
The reported issue is fixed, and the fix published in the below version. Therefore, we kindly request that you upgrade the syncfusion_flutter_charts package to the latest version below to avoid this issue.
Version: https://pub.dev/packages/syncfusion_flutter_charts/versions/26.2.10
Root cause: Having all data points with the same value leads to a zero range, causing division by zero and resulting in NaN for axis height calculations.
Regards,
Preethika Selvam.
Bug description
Sparklinechart is throwing following error if all the entries in the data array are same for example [3.0, 3.0, 3.0, 3.0, 3.0, 3.0]
he following assertion was thrown during paint(): Offset argument contained a NaN value. 'dart:ui/painting.dart': Failed assertion: line 36 pos 10: ''
The relevant error-causing widget was: SfSparkLineChart SfSparkLineChart:file:///Users/abhijitmazumder/development/projects/flutter/mynotes/lib/screens/mood_tracker/components/mood_finish_flow_page.dart:205:28
When the exception was thrown, this was the stack:
2 _offsetIsValid (dart:ui/painting.dart:36:10)
painting.dart:36
3 _NativeCanvas.drawLine (dart:ui/painting.dart:5918:12)
painting.dart:5918
4 RenderSparkChart.renderAxisline (package:syncfusion_flutter_charts/src/sparkline/renderers/renderer_base.dart:650:16)
renderer_base.dart:650
5 RenderSparkChart.paint (package:syncfusion_flutter_charts/src/sparkline/renderers/renderer_base.dart:712:5)
renderer_base.dart:712
6 _RenderSparkLineChart.paint (package:syncfusion_flutter_charts/src/sparkline/renderers/spark_line_renderer.dart:399:11)
spark_line_renderer.dart:399
7 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3239:7)
object.dart:3239
8 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:250:13)
object.dart:250
Steps to reproduce
Have a sparkline chart like this SfSparkLineChart( color: context.primaryColor, axisLineWidth: 1, axisCrossesAt: 3, data: const [3.0, 3.0, 3.0, 3.0, 3.0, 3.0], )
throws error
change any one entry SfSparkLineChart( color: context.primaryColor, axisLineWidth: 1, axisCrossesAt: 3, data: const [3.0, 4.0, 3.0, 3.0, 3.0, 3.0], ) works fine
Code sample
Code sample
```dart SfSparkLineChart( color: context.primaryColor, axisLineWidth: 1, axisCrossesAt: 3, data: const [3.0, 3.0, 3.0, 3.0, 3.0, 3.0], ) ```Screenshots or Video
Screenshots / Video demonstration
NoneStack Traces
Stack Traces
```dart ════════ Exception caught by rendering library ═════════════════════════════════ The following assertion was thrown during paint(): Offset argument contained a NaN value. 'dart:ui/painting.dart': Failed assertion: line 36 pos 10: 'On which target platforms have you observed this bug?
iOS
Flutter Doctor output
Doctor output
```console ✓] Flutter (Channel stable, 3.22.3, on macOS 14.4.1 23E224 darwin-arm64, locale en-IN) • Flutter version 3.22.3 on channel stable at /Users/abhijitmazumder/development/tooling/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision b0850beeb2 (2 weeks ago), 2024-07-16 21:43:41 -0700 • Engine revision 235db911ba • Dart version 3.4.4 • DevTools version 2.34.3 [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1) • Android SDK at /Users/abhijitmazumder/Library/Android/sdk • Platform android-34, build-tools 33.0.1 • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.3) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15E204a • CocoaPods version 1.15.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2024.1) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314) [✓] VS Code (version 1.92.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.94.0 [✓] Connected device (5 available) • sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64 • Android 13 (API 33) (emulator) • iPhone (2) (mobile) • 00008110-001651E41E78401E • ios • iOS 16.2 20C65 • macOS (desktop) • macos • darwin-arm64 • macOS 14.4.1 23E224 darwin-arm64 • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 14.4.1 23E224 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 127.0.6533.89 [✓] Network resources • All expected network resources are available. • No issues found! ```