forked from imaNNeo/fl_chart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscatter_chart_sample2.dart
125 lines (118 loc) · 3.93 KB
/
scatter_chart_sample2.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
class ScatterChartSample2 extends StatefulWidget {
@override
State<StatefulWidget> createState() => _ScatterChartSample2State();
}
class _ScatterChartSample2State extends State {
int touchedIndex;
Color greyColor = Colors.grey;
List<int> selectedSpots = [];
int lastPanStartOnIndex = -1;
@override
Widget build(BuildContext context) {
return AspectRatio(
aspectRatio: 1,
child: Card(
color: const Color(0xff222222),
child: ScatterChart(
ScatterChartData(
scatterSpots: [
ScatterSpot(
4,
4,
color: selectedSpots.contains(0) ? Colors.green : greyColor,
),
ScatterSpot(
2,
5,
color: selectedSpots.contains(1) ? Colors.yellow : greyColor,
radius: 12,
),
ScatterSpot(
4,
5,
color: selectedSpots.contains(2) ? Colors.purpleAccent : greyColor,
radius: 8,
),
ScatterSpot(
8,
6,
color: selectedSpots.contains(3) ? Colors.orange : greyColor,
radius: 20,
),
ScatterSpot(
5,
7,
color: selectedSpots.contains(4) ? Colors.brown : greyColor,
radius: 14,
),
ScatterSpot(
7,
2,
color: selectedSpots.contains(5) ? Colors.lightGreenAccent : greyColor,
radius: 18,
),
ScatterSpot(
3,
2,
color: selectedSpots.contains(6) ? Colors.red : greyColor,
radius: 36,
),
ScatterSpot(
2,
8,
color: selectedSpots.contains(7) ? Colors.tealAccent : greyColor,
radius: 22,
),
],
minX: 0,
maxX: 10,
minY: 0,
maxY: 10,
borderData: FlBorderData(
show: false,
),
gridData: FlGridData(
show: true,
drawHorizontalLine: true,
checkToShowHorizontalLine: (value) => true,
getDrawingHorizontalLine: (value) => FlLine(color: Colors.white.withOpacity(0.1)),
drawVerticalLine: true,
checkToShowVerticalLine: (value) => true,
getDrawingVerticalLine: (value) => FlLine(color: Colors.white.withOpacity(0.1)),
),
titlesData: FlTitlesData(
show: false,
),
showingTooltipIndicators: selectedSpots,
scatterTouchData: ScatterTouchData(
enabled: true,
handleBuiltInTouches: false,
touchTooltipData: ScatterTouchTooltipData(
tooltipBgColor: Colors.black,
),
touchCallback: (ScatterTouchResponse touchResponse) {
if (touchResponse.touchInput is FlPanStart) {
lastPanStartOnIndex = touchResponse.touchedSpotIndex;
} else if (touchResponse.touchInput is FlPanEnd) {
final FlPanEnd flPanEnd = touchResponse.touchInput;
if (flPanEnd.velocity.pixelsPerSecond <= const Offset(4, 4)) {
// Tap happened
setState(() {
if (selectedSpots.contains(lastPanStartOnIndex)) {
selectedSpots.remove(lastPanStartOnIndex);
} else {
selectedSpots.add(lastPanStartOnIndex);
}
});
}
}
},
),
),
),
),
);
}
}