SfCartesianChart(
onAxisLabelRender: (args) {
if (args.axisName == 'primaryYAxis') {
// Converted the axis label value which is in millisecondsSinceEpoch and parsed the
// required date-time values in the string format (min:sec:millisec) and passed into
// axis label’s text argument variable.
args.text =
DateTime.fromMillisecondsSinceEpoch(args.value.toInt())
.minute
.toString() +
':' +
DateTime.fromMillisecondsSinceEpoch(args.value.toInt())
.second
.toString() +
':' +
DateTime.fromMillisecondsSinceEpoch(args.value.toInt())
.millisecond
.toString();
}
},
primaryXAxis: CategoryAxis(),
primaryYAxis: NumericAxis(
// Assigned a name for the y-axis in order to use it in the callback event.
name: 'primaryYAxis'),
series: <ChartSeries<SwinData, String>>[
ColumnSeries<SwinData, String>(
dataSource: chartData,
xValueMapper: (SwinData data, _) => data.playerName,
yValueMapper: (SwinData data, _) {
// Passing the datetime values in milliseconds in to the chart
return data.finishTime.millisecondsSinceEpoch;
},
dataLabelSettings: DataLabelSettings(isVisible: true),
markerSettings: MarkerSettings(isVisible: true))
]
) |
onTooltipRender: (args) {
String yValue = args.dataPoints[args.pointIndex].y.toString();
args.text =
DateTime.fromMillisecondsSinceEpoch(int.parse(yValue))
.minute
.toString() +
':' +
DateTime.fromMillisecondsSinceEpoch(int.parse(yValue))
.second
.toString() +
':' +
DateTime.fromMillisecondsSinceEpoch(int.parse(yValue))
.millisecond
.toString();
}, |
Hello, I have updated the Syncfusion version but now the onAxisLabelRender is not anymore available. How can I proceed in order to have rendered the Y axis with minutes:seconds:milliseconds?
Thank you
Gianfranco
Hi Romeo,
We recommend the axisLabelFormatter callback instead of onAxisLabelRender because we have removed the onAxisLabelRender callback in the chart from the 19.4.38 version and have the callback axisLabelFormatter inside the axis to customize the axis label. So, you can use this callback and customize the axis label in the respective axis. We have attached the code snippet below to achieve your requirement.
Code snippet:
primaryYAxis: NumericAxis( axisLabelFormatter: (args) { String text = DateTime.fromMillisecondsSinceEpoch(int.parse(args.text)) .minute .toString() + ':' + DateTime.fromMillisecondsSinceEpoch(int.parse(args.text)) .second .toString() + ':' + DateTime.fromMillisecondsSinceEpoch(int.parse(args.text)) .millisecond .toString(); return ChartAxisLabel(text, args.textStyle); }, rangePadding: ChartRangePadding.additional, name: 'primaryYAxis'), |
UG: https://help.syncfusion.com/flutter/cartesian-charts/callbacks#axislabelformatter
If you have any queries, please get back to us.
Regards,
Yuvaraj.