-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Line Chart Overlap and Repeat Points by Loading Data from Future #986
Comments
Please provide me a reproducible code in a main.dart file. |
I have the same issue. |
@aqoong Any reproducible code? |
This is my draw widget.
|
Live update a LineChart by adding data to the spot list worked fine pre 0.50.0 but I now get an exception repeatedly, Once I stop updating it the chart appears.. ════════ Exception caught by rendering library ═════════════════════════════════ The relevant error-causing widget was |
I am also seeing this issue now. |
Is there any solution?? |
I find if no initialization LineChartBarData's spots will get this error. but some times data source is dynamic. |
Please see a reproducible example below. The import 'package:flutter/material.dart';
import 'package:fl_chart/fl_chart.dart';
import 'dart:async';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
List<FlSpot> points = [];
bool show_me = true; //initialize to false to workaround mostLeftSpot error
@override
void initState() {
super.initState();
Timer(const Duration(milliseconds: 1000), () {
setState(() {
points.add(FlSpot(5, 5));
show_me = true;
});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: LineChart(
swapAnimationDuration: const Duration(milliseconds: 0),
LineChartData(
minY: 0,
minX: 0,
maxY: 10,
maxX: 10,
lineBarsData: [
LineChartBarData(
spots: points,
show : show_me,
dotData: FlDotData(
show: true,
),
),
],
),
),
);
}
} |
Another workaround which works for me. Set your points list to new one in class MyChart extends StatefulWidget {
List<FlSpot> points = [];
MyChart({super.key});
@override
State<MyChart> createState() => MyChartState();
}
class MyChartState extends State<MyChart> {
@override
Widget build(BuildContext context) {
return LineChart(
LineChartData(
minX: 0,
maxX: 10,
minY: 0,
maxY: 100,
lineBarsData: [LineChartBarData(spots: widget.points)]),
);
}
void changePoints(List<FlSpot> newPoints) {
setState(() {
widget.points = newPoints;
});
}
} I have my |
Just add show property at LineChartBarData, this will remove your exception LineChartBarData(
show: spotsList.isNotEmpty, // do not show LineChartBarData when spotsList his empty, make sure spotsList is not null
spots: spotsList
) |
Hello, I have a problem the chart repeats itself and overlaps random by Hot Reload my App
here you can see what i mean
https://imgur.com/a/xGct2NN
I load Data from Sqflite and add to my list, here is my Code
The text was updated successfully, but these errors were encountered: