fl_chart
fl_chart copied to clipboard
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.
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<PlotDataManager?>], 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
https://github.com/imaNNeoFighT/fl_chart/pull/1142
I couldn't reproduce it. There's no exception, and below is the result of your code in my machine (latest fl_chart version, 0.55.1):
Please give me a valid reproducible code (a main.dart file). Or a video shot of what you're facing.
Hi,
To reproduce: https://github.com/imaNNeoFighT/fl_chart/pull/1142#issue-1366216416
Fixed the issue in this PR https://github.com/imaNNeoFighT/fl_chart/pull/1142/commits/36701547c8d86e3172e6c8c66912548f3556b68b
It is awaiting approval to merge.
I followed the contributing steps and it still failed. Can you help me understand why?
@imaNNeoFighT can you guide me?
Please give me a valid reproducible code (a main.dart file). Or a video shot of what you're facing.
LineChartBarData(
spots: spots,
dotData: FlDotData(show: false),
color: Colors.blue,
),
LineChartBarData(
spots: spots2,
dotData: FlDotData(show: false),
color: Colors.green,
),
LineChartBarData(
spots: null,
dotData: FlDotData(show: false),
color: Colors.yellow,
),
I am having the same issue, Try with multiple LineChartBarData, with one being completely null.
Hi everyone! The code checks max position X and Y coordinates by spot elements. If your spot list is empty or null, use [FlSpot.zero] for the spot list by default. It helped me. Don't use [FlSpot.nullSpot]