forked from imaNNeo/fl_chart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
line_chart_sample5.dart
100 lines (96 loc) · 2.94 KB
/
line_chart_sample5.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
class LineChartSample5 extends StatelessWidget {
final List<int> showIndexes = const [1, 3, 5];
@override
Widget build(BuildContext context) {
final lineBarsData = [
LineChartBarData(
showingIndicators: showIndexes,
spots: [
FlSpot(0, 1),
FlSpot(1, 2),
FlSpot(2, 1.5),
FlSpot(3, 3),
FlSpot(4, 3.5),
FlSpot(5, 5),
FlSpot(6, 8),
],
isCurved: true,
barWidth: 4,
belowBarData: BarAreaData(
show: true,
),
dotData: FlDotData(show: false),
),
];
final LineChartBarData tooltipsOnBar = lineBarsData[0];
return SizedBox(
width: 300,
height: 140,
child: LineChart(
LineChartData(
showingTooltipIndicators: showIndexes.map((index) {
return MapEntry(
index,
[
LineBarSpot(tooltipsOnBar, lineBarsData.indexOf(tooltipsOnBar), tooltipsOnBar.spots[index]),
],
);
}).toList(),
lineTouchData: LineTouchData(
enabled: false,
touchTooltipData: LineTouchTooltipData(
tooltipBgColor: Colors.pink,
tooltipRoundedRadius: 8,
getTooltipItems: (List<LineBarSpot> lineBarsSpot) {
return lineBarsSpot.map((lineBarSpot) {
return LineTooltipItem(
lineBarSpot.y.toString(),
TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
);
}).toList();
})),
lineBarsData: lineBarsData,
minY: 0,
titlesData: FlTitlesData(
leftTitles: const SideTitles(
showTitles: false,
),
bottomTitles: SideTitles(
showTitles: true,
getTitles: (val) {
switch (val.toInt()) {
case 0:
return '00:00';
case 1:
return '04:00';
case 2:
return '08:00';
case 3:
return '12:00';
case 4:
return '16:00';
case 5:
return '20:00';
case 6:
return '23:59';
}
return '';
},
textStyle: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.blueGrey,
fontFamily: 'Digital',
fontSize: 18,
)),
),
gridData: const FlGridData(show: false),
borderData: FlBorderData(
show: true,
),
),
),
);
}
}