Callbacks in Syncfusion Flutter charts
Callbacks in Circular Charts
The below Callbacks are for Circular chart.
onLegendItemRender
Triggers when the legend item is rendering. Here, you can customize the legend’s text, and shape. The onLegendItemRender
Callback contains the following arguments.
-
text
- specifies the content of the legend. -
pointIndex
- specifies the current point index that is applicable for circular chart type alone. -
seriesIndex
- specifies the current series index. -
legendIconType
- specifies the shape of the legend.
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: SfCircularChart(
legend: Legend(isVisible: true),
onLegendItemRender: (LegendRenderArgs args){
args.text = 'Legend Text';
args.legendIconType = LegendIconType.diamond;
}
)
)
);
}
onTooltipRender
Triggers while tooltip is rendering. Here, you can customize the text, header, x and y-positions. The onTooltipRender
Callback contains the following arguments.
-
text
- specifies the content of the tooltip. -
header
- specifies the header content of the tooltip. -
locationX
- specifies the x position of tooltip. -
locationY
- specifies the y position of tooltip. -
seriesIndex
- specifies the current series index. -
dataPoints
- holds the data point collection. -
pointIndex
- specifies the current point index.
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: SfCircularChart(
onTooltipRender: (TooltipArgs args){
args.text = 'Custom Text';
},
tooltipBehavior: TooltipBehavior(enable: true),
)
)
);
}
onDataLabelRender
Triggers when data label is rendering. Text and text styles such as color, font size, and font weight can be customized. The onDataLabelRender
Callback contains the following arguments.
-
text
- specifies the content of the data label. -
textStyle
– used to change the text color, size, font family, font style, and font weight. -
pointIndex
- specifies the current point index. -
series
- specifies current series.
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: SfCircularChart(
onDataLabelRender:(DataLabelRenderArgs args){
args.text = 'Data label';
},
series: <CircularSeries>[
PieSeries<ChartData, String>(
dataLabelSettings: DataLabelSettings(
isVisible: true
)
)
]
)
)
);
}
onPointTapped
Triggers when tapping the series point. The onPointTapped
Callback contains the following arguments.
-
seriesIndex
- specifies the current series index. -
pointIndex
- specifies the current point index. -
dataPoints
- holds the data point collection.
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: SfCircularChart(
onPointTapped: (PointTapArgs args){
print(args.seriesIndex);
print(args.pointIndex);
}
)
);
}
onLegendTapped
Triggers when tapping the legend item. The onLegendTapped
Callback contains the following arguments.
-
seriesIndex
- specifies the current series index. -
pointIndex
- specifies the current point index that is applicable for circular series. -
series
- specifies the current series.
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: SfCircularChart(
onLegendTapped: (LegendTapArgs args) {
print(args.seriesIndex);
},
legend: Legend(isVisible: true)
)
);
}
onSelectionChanged
Triggers while selection changes. Here you can customize the selectedColor, unselectedColor, selectedBorderColor, selectedBorderWidth, unselectedBorderColor, and unselectedBorderWidth properties. The onSelectionChanged
Callback contains the following arguments.
-
series
- specifies current series. -
seriesIndex
- specifies the current series index. -
pointIndex
- specifies the current point index. -
selectedColor
- specifies color of the selected data points or series. -
unselectedColor
- specifies color of the unselected data points or series. -
selectedBorderColor
- specifies border color of the selected data points or series. -
selectedBorderWidth
- specifies border width of the selected data points or series. -
unselectedBorderColor
- specifies border color of the unselected data points or series. -
unselectedBorderWidth
- specifies border width of the unselected data points or series.
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: SfCircularChart(
onSelectionChanged: (SelectionArgs args){
args.selectedColor = Colors.red;
args.unselectedColor = Colors.lightGreen;
},
series: <CircularSeries>[
PieSeries<ChartData, String>(
selectionSettings: SelectionSettings(
enable: true
)
)
]
)
);
}