Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Exception if legend enabled but series are empty #165

Open
farconada opened this issue Nov 4, 2018 · 2 comments
Open

Exception if legend enabled but series are empty #165

farconada opened this issue Nov 4, 2018 · 2 comments

Comments

@farconada
Copy link

flutter: RangeError (index): Invalid value: Valid value range is empty: 0
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0 List.[] (dart:core/runtime/libgrowable_array.dart:145:60)
flutter: #1 new Series. (package:charts_common/src/data/series.dart:85:61)
flutter: #2 PerSeriesLegendEntryGenerator.getLegendEntries. (package:charts_common/src/chart/common/behavior/legend/per_series_legend_entry_generator.dart:42:27)
flutter: #3 MappedListIterable.elementAt (dart:_internal/iterable.dart:414:29)
flutter: #4 ListIterable.toList (dart:_internal/iterable.dart:219:19)
flutter: #5 PerSeriesLegendEntryGenerator.getLegendEntries (package:charts_common/src/chart/common/behavior/legend/per_series_legend_entry_generator.dart:43:10)
flutter: #6 Legend._postProcess (package:charts_common/src/chart/common/behavior/legend/legend.dart:188:32)
flutter: #7 BaseChart.fireOnPostprocess. (package:charts_common/src/chart/common/base_chart.dart:572:18)
flutter: #8 List.forEach (dart:core/runtime/libgrowable_array.dart:278:8)
flutter: #9 BaseChart.fireOnPostprocess (package:charts_common/src/chart/common/base_chart.dart:570:25)
flutter: #10 BaseChart.drawInternal (package:charts_common/src/chart/common/base_chart.dart:437:5)
flutter: #11 BaseChart.draw (package:charts_common/src/chart/common/base_chart.dart:402:5)
flutter: #12 ChartContainerRenderObject.reconfigure (package:charts_flutter/src/chart_container.dart:164:14)
flutter: #13 ChartContainer.createRenderObject (package:charts_flutter/src/chart_container.dart:61:49)
flutter: #14 RenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4418:28)
flutter: #15 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4795:11)
flutter: #16 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2937:14)
flutter: #17 Element.updateChild (package:flutter/src/widgets/framework.dart:2740:12)

@gzfarmer
Copy link

I have the same problem when I try example "Series Legend With Measures". Maybe, the code that make this error is as follows:

new charts.SeriesLegend(
position: charts.BehaviorPosition.top,
horizontalFirst: false,
cellPadding: new EdgeInsets.only(right: 4.0, bottom: 4.0),
showMeasures: true,
measureFormatter: (num value) {
return value == null ? '-' : '${value.toStringAsFixed(2)}k';
},
),

@matsunanaro
Copy link

My app got the same RangeError today, but from line 143 in package:charts_common/src/data/series.dart

final _colorFn = colorFn == null ? null : (int index) => colorFn(data[index], index); // If the data array is empty, it will raise a RangeError at runtime !!!

Suggestion:

final _colorFn = colorFn == null || data.isEmpty ? null : (int index) => colorFn(data[index], index);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants