Right To Left (RTL) in Flutter Circular Chart (SfCircularChart)
13 May 2021 / 3 minutes to read
Circular chart supports right to left rendering. But series and other chart elements rendering will be the same for both LTR and RTL. Only, the legend rendering will be changed.
RLT rendering ways
Right to left rendering can be switched in the following ways:
Wrapping the SfCircularChart with Directionality widget
To change the rendering direction from right to left, you can wrap the SfCircularChart
widget inside the Directionality
widget and set the textDirection
property as TextDirection.rtl.
@override
Widget build(BuildContext context) {
return Scaffold(
body: Directionality(
textDirection: TextDirection.rtl,
child: SfCircularChart(
//...
),
),
);
}
Changing the locale to RTL languages
To change the chart rendering direction from right to left, you can change the locale
to any of the RTL languages such as Arabic, Persian, Hebrew, Pashto, and Urdu.
@override
Widget build(BuildContext context) {
return MaterialApp(
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: <Locale>[
Locale('en'),
Locale('ar'),
// ... other locales the app supports
],
locale: Locale('ar'),
home: Scaffold(
body: SfCircularChart(
//...
),
)
);
}
RTL supported chart elements
Right to left rendering is effective only for the legend in the chart. Legend items will be rendered from right to left direction.
In addition, if you want to change the tooltip’s content, to look like it is rendering from right to left, then you can set the format
property in TooltipBehavior
as "point.y : point.x"
. By default, the tooltip format will be "point.x : point.y"
.
SfCircularChart(
tooltipBehavior: TooltipBehavior(
enable: true,
format: “point.y : point.x”
)
//...
)