Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d88b405

Browse files
committed
added SideTitles class to hold info for draw titles around the chart, and used for leftTitles, topTitles, rightTitles, bottomTitles in the FlTitles class, and updated the painter and samples
1 parent 19cf9e1 commit d88b405

File tree

11 files changed

+463
-313
lines changed

11 files changed

+463
-313
lines changed

example/lib/bar_chart/samples/bar_chart_sample1.dart

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -140,29 +140,32 @@ class BarChartSample1State extends State<BarChartSample1> {
140140
),
141141
titlesData: FlTitlesData(
142142
show: true,
143-
showHorizontalTitles: true,
144-
showVerticalTitles: false,
145-
horizontalTitlesTextStyle: TextStyle(
146-
color: Colors.white, fontWeight: FontWeight.bold, fontSize: 14),
147-
horizontalTitleMargin: 16,
148-
getHorizontalTitles: (double value) {
149-
switch (value.toInt()) {
150-
case 0:
151-
return 'M';
152-
case 1:
153-
return 'T';
154-
case 2:
155-
return 'W';
156-
case 3:
157-
return 'T';
158-
case 4:
159-
return 'F';
160-
case 5:
161-
return 'S';
162-
case 6:
163-
return 'S';
143+
bottomTitles: SideTitles(
144+
showTitles: true,
145+
textStyle: TextStyle(
146+
color: Colors.white, fontWeight: FontWeight.bold, fontSize: 14),
147+
margin: 16,
148+
getTitles: (double value) {
149+
switch (value.toInt()) {
150+
case 0:
151+
return 'M';
152+
case 1:
153+
return 'T';
154+
case 2:
155+
return 'W';
156+
case 3:
157+
return 'T';
158+
case 4:
159+
return 'F';
160+
case 5:
161+
return 'S';
162+
case 6:
163+
return 'S';
164+
}
164165
}
165-
}),
166+
),
167+
leftTitles: SideTitles(showTitles: false,),
168+
),
166169
borderData: FlBorderData(
167170
show: false,
168171
),

example/lib/bar_chart/samples/bar_chart_sample2.dart

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -148,48 +148,52 @@ class BarChartSample2State extends State<BarChartSample2> {
148148
),
149149
titlesData: FlTitlesData(
150150
show: true,
151-
showHorizontalTitles: true,
152-
showVerticalTitles: true,
153-
verticalTitlesTextStyle: TextStyle(
154-
color: Color(0xff7589a2),
155-
fontWeight: FontWeight.bold,
156-
fontSize: 14),
157-
verticalTitleMargin: 32,
158-
verticalTitlesReservedWidth: 14,
159-
getVerticalTitles: (value) {
160-
if (value == 0) {
161-
return "1K";
162-
} else if (value == 10) {
163-
return "5K";
164-
} else if (value == 19) {
165-
return "10K";
166-
} else {
167-
return "";
168-
}
169-
},
170-
horizontalTitlesTextStyle: TextStyle(
171-
color: Color(0xff7589a2),
172-
fontWeight: FontWeight.bold,
173-
fontSize: 14),
174-
horizontalTitleMargin: 20,
175-
getHorizontalTitles: (double value) {
176-
switch (value.toInt()) {
177-
case 0:
178-
return 'Mn';
179-
case 1:
180-
return 'Te';
181-
case 2:
182-
return 'Wd';
183-
case 3:
184-
return 'Tu';
185-
case 4:
186-
return 'Fr';
187-
case 5:
188-
return 'St';
189-
case 6:
190-
return 'Sn';
191-
}
192-
},
151+
bottomTitles: SideTitles(
152+
showTitles: true,
153+
textStyle: TextStyle(
154+
color: const Color(0xff7589a2),
155+
fontWeight: FontWeight.bold,
156+
fontSize: 14),
157+
margin: 20,
158+
getTitles: (double value) {
159+
switch (value.toInt()) {
160+
case 0:
161+
return 'Mn';
162+
case 1:
163+
return 'Te';
164+
case 2:
165+
return 'Wd';
166+
case 3:
167+
return 'Tu';
168+
case 4:
169+
return 'Fr';
170+
case 5:
171+
return 'St';
172+
case 6:
173+
return 'Sn';
174+
}
175+
},
176+
),
177+
leftTitles: SideTitles(
178+
showTitles: true,
179+
textStyle: TextStyle(
180+
color: const Color(0xff7589a2),
181+
fontWeight: FontWeight.bold,
182+
fontSize: 14),
183+
margin: 32,
184+
reservedSize: 14,
185+
getTitles: (value) {
186+
if (value == 0) {
187+
return '1K';
188+
} else if (value == 10) {
189+
return '5K';
190+
} else if (value == 19) {
191+
return '10K';
192+
} else {
193+
return '';
194+
}
195+
},
196+
),
193197
),
194198
borderData: FlBorderData(
195199
show: false,

example/lib/line_chart/samples/line_chart_sample1.dart

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -71,39 +71,46 @@ class LineChartSample1State extends State<LineChartSample1> {
7171
show: false,
7272
),
7373
titlesData: FlTitlesData(
74-
horizontalTitlesTextStyle: TextStyle(
75-
color: Color(0xff72719b),
76-
fontWeight: FontWeight.bold,
77-
fontSize: 16,
74+
bottomTitles: SideTitles(
75+
showTitles: true,
76+
reservedSize: 22,
77+
textStyle: TextStyle(
78+
color: const Color(0xff72719b),
79+
fontWeight: FontWeight.bold,
80+
fontSize: 16,
81+
),
82+
margin: 10,
83+
getTitles: (value) {
84+
switch(value.toInt()) {
85+
case 2:
86+
return 'SEPT';
87+
case 7:
88+
return 'OCT';
89+
case 12:
90+
return 'DEC';
91+
}
92+
return '';
93+
},
7894
),
79-
horizontalTitleMargin: 10,
80-
getHorizontalTitles: (value) {
81-
switch(value.toInt()) {
82-
case 2:
83-
return "SEPT";
84-
case 7:
85-
return "OCT";
86-
case 12:
87-
return "DEC";
88-
}
89-
return "";
90-
},
91-
verticalTitlesTextStyle: TextStyle(
92-
color: Color(0xff75729e),
93-
fontWeight: FontWeight.bold,
94-
fontSize: 14,
95+
leftTitles: SideTitles(
96+
showTitles: true,
97+
textStyle: TextStyle(
98+
color: Color(0xff75729e),
99+
fontWeight: FontWeight.bold,
100+
fontSize: 14,
101+
),
102+
getTitles: (value) {
103+
switch(value.toInt()) {
104+
case 1: return '1m';
105+
case 2: return '2m';
106+
case 3: return '3m';
107+
case 4: return '5m';
108+
}
109+
return '';
110+
},
111+
margin: 8,
112+
reservedSize: 30,
95113
),
96-
getVerticalTitles: (value) {
97-
switch(value.toInt()) {
98-
case 1: return "1m";
99-
case 2: return "2m";
100-
case 3: return "3m";
101-
case 4: return "5m";
102-
}
103-
return "";
104-
},
105-
verticalTitleMargin: 8,
106-
verticalTitlesReservedWidth: 30,
107114
),
108115
borderData: FlBorderData(
109116
show: true,

example/lib/line_chart/samples/line_chart_sample2.dart

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,36 +39,43 @@ class LineChartSample2 extends StatelessWidget {
3939
),
4040
titlesData: FlTitlesData(
4141
show: true,
42-
horizontalTitlesTextStyle: TextStyle(
43-
color: Color(0xff68737d),
44-
fontWeight: FontWeight.bold,
45-
fontSize: 16
46-
),
47-
getHorizontalTitles: (value) {
48-
switch(value.toInt()) {
49-
case 2: return "MAR";
50-
case 5: return "JUN";
51-
case 8: return "SEP";
52-
}
42+
bottomTitles: SideTitles(
43+
showTitles: true,
44+
reservedSize: 22,
45+
textStyle: TextStyle(
46+
color: const Color(0xff68737d),
47+
fontWeight: FontWeight.bold,
48+
fontSize: 16
49+
),
50+
getTitles: (value) {
51+
switch(value.toInt()) {
52+
case 2: return 'MAR';
53+
case 5: return 'JUN';
54+
case 8: return 'SEP';
55+
}
5356

54-
return "";
55-
},
56-
verticalTitlesTextStyle: TextStyle(
57-
color: Color(0xff67727d),
58-
fontWeight: FontWeight.bold,
59-
fontSize: 15,
57+
return '';
58+
},
59+
margin: 8,
60+
),
61+
leftTitles: SideTitles(
62+
showTitles: true,
63+
textStyle: TextStyle(
64+
color: const Color(0xff67727d),
65+
fontWeight: FontWeight.bold,
66+
fontSize: 15,
67+
),
68+
getTitles: (value) {
69+
switch(value.toInt()) {
70+
case 1: return '10k';
71+
case 3: return '30k';
72+
case 5: return '50k';
73+
}
74+
return '';
75+
},
76+
reservedSize: 28,
77+
margin: 12,
6078
),
61-
getVerticalTitles: (value) {
62-
switch(value.toInt()) {
63-
case 1: return "10k";
64-
case 3: return "30k";
65-
case 5: return "50k";
66-
}
67-
return "";
68-
},
69-
verticalTitlesReservedWidth: 28,
70-
verticalTitleMargin: 12,
71-
horizontalTitleMargin: 8,
7279
),
7380
borderData: FlBorderData(
7481
show: true,

example/lib/line_chart/samples/line_chart_sample3.dart

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -152,28 +152,35 @@ class LineChartSample3 extends StatelessWidget {
152152
),
153153
titlesData: FlTitlesData(
154154
show: true,
155-
getHorizontalTitles: (value) {
156-
return weekDays[value.toInt()];
157-
},
158-
getVerticalTitles: (value) {
159-
switch (value.toInt()) {
160-
case 0:
161-
return "";
162-
case 1:
163-
return "1k colories";
164-
case 2:
165-
return "2k colories";
166-
case 3:
167-
return "3k colories";
168-
}
155+
leftTitles: SideTitles(
156+
showTitles: true,
157+
getTitles: (value) {
158+
switch (value.toInt()) {
159+
case 0:
160+
return '';
161+
case 1:
162+
return '1k colories';
163+
case 2:
164+
return '2k colories';
165+
case 3:
166+
return '3k colories';
167+
}
169168

170-
return "";
171-
},
172-
horizontalTitlesTextStyle: TextStyle(
173-
color: Colors.deepOrange,
174-
fontWeight: FontWeight.bold,
169+
return '';
170+
},
171+
textStyle: const TextStyle(color: Colors.black, fontSize: 10),
175172
),
176-
verticalTitlesTextStyle: TextStyle(color: Colors.black, fontSize: 10)),
173+
bottomTitles: SideTitles(
174+
showTitles: true,
175+
getTitles: (value) {
176+
return weekDays[value.toInt()];
177+
},
178+
textStyle: const TextStyle(
179+
color: Colors.deepOrange,
180+
fontWeight: FontWeight.bold,
181+
),
182+
)
183+
),
177184
),
178185
),
179186
),

0 commit comments

Comments
 (0)