Skip to content

Commit cad2ad9

Browse files
flut-5993-[bug][flutter]: axislabelformatter changed
1 parent 33d85dd commit cad2ad9

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

lib/main.dart

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,33 +38,35 @@ class _MyHomePageState extends State<MyHomePage> {
3838
height: 500,
3939
child: SfCartesianChart(
4040
borderWidth: 10,
41-
primaryXAxis: CategoryAxis(),
41+
primaryXAxis: CategoryAxis(
42+
axisLabelFormatter: (AxisLabelRenderDetails args) {
43+
late String text;
44+
late TextStyle textStyle;
45+
if (args.axis.name == 'primaryXAxis') {
46+
text = '${args.text}st\nMonth';
47+
if (args.text == 'Jan')
48+
textStyle = args.textStyle
49+
.copyWith(fontFamily: 'DancingScript');
50+
if (args.text == 'Feb')
51+
textStyle =
52+
args.textStyle.copyWith(color: Colors.green);
53+
if (args.text == 'Mar')
54+
textStyle = args.textStyle.copyWith(fontSize: 15);
55+
if (args.text == 'Apr')
56+
textStyle = args.textStyle
57+
.copyWith(fontStyle: FontStyle.italic);
58+
if (args.text == 'May')
59+
textStyle = args.textStyle
60+
.copyWith(fontWeight: FontWeight.bold);
61+
} else {
62+
text = args.text;
63+
textStyle = args.textStyle;
64+
}
65+
return ChartAxisLabel(text, textStyle);
66+
},
67+
),
4268
primaryYAxis: NumericAxis(minimum: 20),
4369
backgroundColor: Colors.white,
44-
axisLabelFormatter: (AxisLabelRenderDetails args) {
45-
late String text;
46-
late TextStyle textStyle;
47-
if (args.axisName == 'primaryXAxis') {
48-
text = '${args.text}st\nMonth';
49-
if (args.text == 'Jan')
50-
textStyle =
51-
args.textStyle.copyWith(fontFamily: 'DancingScript');
52-
if (args.text == 'Feb')
53-
textStyle = args.textStyle.copyWith(color: Colors.green);
54-
if (args.text == 'Mar')
55-
textStyle = args.textStyle.copyWith(fontSize: 15);
56-
if (args.text == 'Apr')
57-
textStyle =
58-
args.textStyle.copyWith(fontStyle: FontStyle.italic);
59-
if (args.text == 'May')
60-
textStyle =
61-
args.textStyle.copyWith(fontWeight: FontWeight.bold);
62-
} else {
63-
text = args.text;
64-
textStyle = args.textStyle;
65-
}
66-
return ChartAxisLabel(text, textStyle);
67-
},
6870
series: <ChartSeries<SalesData, String>>[
6971
LineSeries<SalesData, String>(
7072
dataSource: <SalesData>[

0 commit comments

Comments
 (0)