Skip to content

Commit 4790faa

Browse files
committed
Add colors to chart
1 parent 7244214 commit 4790faa

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

lib/screens/chart.dart

+20-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ import 'package:flutter/material.dart';
1010
import '../models/node.dart';
1111
import '../theme.dart';
1212

13+
const colors = [
14+
Color(0xff005e83),
15+
Color(0xff00a072),
16+
Color(0xfff7b500),
17+
Color(0xffe06f00),
18+
Color(0xffbb1f11),
19+
Color(0xff883e8d),
20+
];
21+
1322
class LiveChart extends StatelessWidget {
1423
final NodeModel node;
1524
final startTime = DateTime.now().millisecondsSinceEpoch;
@@ -21,6 +30,14 @@ class LiveChart extends StatelessWidget {
2130

2231
LiveChart({super.key, required this.node});
2332

33+
Color _getChipColor(String name) {
34+
if (node.selectedSeries.contains(name)) {
35+
return colors[node.selectedSeries.indexOf(name) % colors.length];
36+
} else {
37+
return Colors.grey;
38+
}
39+
}
40+
2441
@override
2542
Widget build(BuildContext context) {
2643
return Column(
@@ -52,6 +69,7 @@ class LiveChart extends StatelessWidget {
5269
}
5370
},
5471
showCheckmark: false,
72+
selectedColor: _getChipColor(name),
5573
))
5674
.toList(),
5775
),
@@ -123,9 +141,8 @@ class LiveChart extends StatelessWidget {
123141
LineChartBarData(
124142
spots: node.timeseries[series]!,
125143
isCurved: true,
126-
gradient: LinearGradient(
127-
colors: gradientColors,
128-
),
144+
preventCurveOverShooting: true,
145+
color: colors[node.selectedSeries.indexOf(series) % colors.length],
129146
barWidth: 3,
130147
isStrokeCapRound: true,
131148
dotData: const FlDotData(

0 commit comments

Comments
 (0)