imaNNeo / imaNNeo/fl_chart

If the Chart Data is empty and no limits are provided to axis, it should not throw an exception but it should default to a value.

Open
#1,141 8 comments 0 reactions 0 assignees View on GitHub
Line Chart Needs Reproducible Code
Dominant language
Dart
Stars
7.6k
Forks
2k
Avg merge
9d 1h
Merged PRs (30d)
2

Description

if no max/min is provided in both axis and if there is no data, I believe it should default to min = 0, max = 1.

In my application I am displaying live RSSI data of BLE devices. When no BLE device is detected horizontal axis (time) is irrelevant. My chart computes X axis values from the x field of FlSpot x values.

**Describe the bug**
When LineChartData is empty and maxX is null it throws the following exception:
```
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following LateError was thrown building RSSIChart(dirty, dependencies:
[_InheritedProviderScope], state: _RSSIChartState#77d4d):
LateInitializationError: Field 'mostRightSpot' has not been initialized.

The relevant error-causing widget was:
RSSIChart
RSSIChart:file:///C:/Users/kutlay.hanli/AndroidStudioProjects/adi_attach/lib/main.dart:52:19

When the exception was thrown, this was the stack:
#0 LineChartBarData.mostRightSpot (package:fl_chart/src/chart/line_chart/line_chart_data.dart)
#1 LineChartHelper.calculateMaxAxisValues (package:fl_chart/src/chart/line_chart/line_chart_helper.dart:49:19)
#2 new LineChartData (package:fl_chart/src/chart/line_chart/line_chart_data.dart:93:31)
```

**To Reproduce**
```
Scaffold(
body: SafeArea(
child: LineChart(
LineChartData(
lineBarsData: null,
maxY: -30,
minY: -150,
),
),
),
);
```

**Versions**
```
Flutter 3.0.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision f1875d570e (8 weeks ago) • 2022-07-13 11:24:16 -0700
Engine • revision e85ea0e79c
Tools • Dart 2.17.6 • DevTools 2.12.2

fl_chart: ^0.55.1
```

Contributor guide

Open the contributing guide

Research direction

Start with lib/src/chart/line_chart/line_chart_data.dart and lib/src/chart/line_chart/line_chart_helper.dart, especially the constructor and calculateMaxAxisValues path shown in the stack trace. Run the supplied empty LineChartData reproduction first. Done means empty line data with no axis limits no longer throws and receives the requested default range of min 0 and max 1.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, flutter
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.