@@ -83,106 +83,103 @@ class BarChartSample2State extends State<BarChartSample2> {
83
83
height: 38 ,
84
84
),
85
85
Expanded (
86
- child: Padding (
87
- padding: const EdgeInsets .symmetric (horizontal: 8.0 ),
88
- child: BarChart (
89
- BarChartData (
90
- maxY: 20 ,
91
- barTouchData: BarTouchData (
92
- touchTooltipData: BarTouchTooltipData (
93
- tooltipBgColor: Colors .grey,
94
- getTooltipItem: (_a, _b, _c, _d) => null ,
95
- ),
96
- touchCallback: (FlTouchEvent event, response) {
97
- if (response == null || response.spot == null ) {
98
- setState (() {
99
- touchedGroupIndex = - 1 ;
100
- showingBarGroups = List .of (rawBarGroups);
101
- });
102
- return ;
103
- }
104
-
105
- touchedGroupIndex = response.spot! .touchedBarGroupIndex;
106
-
86
+ child: BarChart (
87
+ BarChartData (
88
+ maxY: 20 ,
89
+ barTouchData: BarTouchData (
90
+ touchTooltipData: BarTouchTooltipData (
91
+ tooltipBgColor: Colors .grey,
92
+ getTooltipItem: (_a, _b, _c, _d) => null ,
93
+ ),
94
+ touchCallback: (FlTouchEvent event, response) {
95
+ if (response == null || response.spot == null ) {
107
96
setState (() {
108
- if (! event.isInterestedForInteractions) {
109
- touchedGroupIndex = - 1 ;
110
- showingBarGroups = List .of (rawBarGroups);
111
- return ;
112
- }
97
+ touchedGroupIndex = - 1 ;
113
98
showingBarGroups = List .of (rawBarGroups);
114
- if (touchedGroupIndex != - 1 ) {
115
- var sum = 0.0 ;
116
- for (var rod in showingBarGroups[touchedGroupIndex].barRods) {
117
- sum += rod.y;
118
- }
119
- final avg =
120
- sum / showingBarGroups[touchedGroupIndex].barRods.length;
99
+ });
100
+ return ;
101
+ }
121
102
122
- showingBarGroups[touchedGroupIndex] =
123
- showingBarGroups[touchedGroupIndex].copyWith (
124
- barRods: showingBarGroups[touchedGroupIndex].barRods.map ((rod) {
125
- return rod.copyWith (y: avg);
126
- }).toList (),
127
- );
103
+ touchedGroupIndex = response.spot! .touchedBarGroupIndex;
104
+
105
+ setState (() {
106
+ if (! event.isInterestedForInteractions) {
107
+ touchedGroupIndex = - 1 ;
108
+ showingBarGroups = List .of (rawBarGroups);
109
+ return ;
110
+ }
111
+ showingBarGroups = List .of (rawBarGroups);
112
+ if (touchedGroupIndex != - 1 ) {
113
+ var sum = 0.0 ;
114
+ for (var rod in showingBarGroups[touchedGroupIndex].barRods) {
115
+ sum += rod.y;
128
116
}
129
- });
130
- }),
131
- titlesData: FlTitlesData (
132
- show: true ,
133
- rightTitles: SideTitles (showTitles: false ),
134
- topTitles: SideTitles (showTitles: false ),
135
- bottomTitles: SideTitles (
136
- showTitles: true ,
137
- getTextStyles: (context, value) => const TextStyle (
138
- color: Color (0xff7589a2 ), fontWeight: FontWeight .bold, fontSize: 14 ),
139
- margin: 20 ,
140
- getTitles: (double value) {
141
- switch (value.toInt ()) {
142
- case 0 :
143
- return 'Mn' ;
144
- case 1 :
145
- return 'Te' ;
146
- case 2 :
147
- return 'Wd' ;
148
- case 3 :
149
- return 'Tu' ;
150
- case 4 :
151
- return 'Fr' ;
152
- case 5 :
153
- return 'St' ;
154
- case 6 :
155
- return 'Sn' ;
156
- default :
157
- return '' ;
117
+ final avg = sum / showingBarGroups[touchedGroupIndex].barRods.length;
118
+
119
+ showingBarGroups[touchedGroupIndex] =
120
+ showingBarGroups[touchedGroupIndex].copyWith (
121
+ barRods: showingBarGroups[touchedGroupIndex].barRods.map ((rod) {
122
+ return rod.copyWith (y: avg);
123
+ }).toList (),
124
+ );
158
125
}
159
- },
160
- ),
161
- leftTitles: SideTitles (
162
- showTitles: true ,
163
- getTextStyles: (context, value) => const TextStyle (
164
- color: Color (0xff7589a2 ), fontWeight: FontWeight .bold, fontSize: 14 ),
165
- margin: 32 ,
166
- reservedSize: 14 ,
167
- getTitles: (value) {
168
- if (value == 0 ) {
169
- return '1K' ;
170
- } else if (value == 10 ) {
171
- return '5K' ;
172
- } else if (value == 19 ) {
173
- return '10K' ;
174
- } else {
126
+ });
127
+ }),
128
+ titlesData: FlTitlesData (
129
+ show: true ,
130
+ rightTitles: SideTitles (showTitles: false ),
131
+ topTitles: SideTitles (showTitles: false ),
132
+ bottomTitles: SideTitles (
133
+ showTitles: true ,
134
+ getTextStyles: (context, value) => const TextStyle (
135
+ color: Color (0xff7589a2 ), fontWeight: FontWeight .bold, fontSize: 14 ),
136
+ margin: 20 ,
137
+ getTitles: (double value) {
138
+ switch (value.toInt ()) {
139
+ case 0 :
140
+ return 'Mn' ;
141
+ case 1 :
142
+ return 'Te' ;
143
+ case 2 :
144
+ return 'Wd' ;
145
+ case 3 :
146
+ return 'Tu' ;
147
+ case 4 :
148
+ return 'Fr' ;
149
+ case 5 :
150
+ return 'St' ;
151
+ case 6 :
152
+ return 'Sn' ;
153
+ default :
175
154
return '' ;
176
- }
177
- },
178
- ),
155
+ }
156
+ },
179
157
),
180
- borderData: FlBorderData (
181
- show: false ,
158
+ leftTitles: SideTitles (
159
+ showTitles: true ,
160
+ getTextStyles: (context, value) => const TextStyle (
161
+ color: Color (0xff7589a2 ), fontWeight: FontWeight .bold, fontSize: 14 ),
162
+ margin: 8 ,
163
+ reservedSize: 28 ,
164
+ interval: 1 ,
165
+ getTitles: (value) {
166
+ if (value == 0 ) {
167
+ return '1K' ;
168
+ } else if (value == 10 ) {
169
+ return '5K' ;
170
+ } else if (value == 19 ) {
171
+ return '10K' ;
172
+ } else {
173
+ return '' ;
174
+ }
175
+ },
182
176
),
183
- barGroups: showingBarGroups,
184
- gridData: FlGridData (show: false ),
185
177
),
178
+ borderData: FlBorderData (
179
+ show: false ,
180
+ ),
181
+ barGroups: showingBarGroups,
182
+ gridData: FlGridData (show: false ),
186
183
),
187
184
),
188
185
),
0 commit comments