pointToPixel method
Converts chart data point value to logical pixel value.
The pointToPixel method takes chart data point value as input and returns logical pixel value.
Since this method is in the series controller, x and y-axis associated with this particular series will be considering for conversion value.
Widget build(BuildContext context) {
ChartSeriesController? _chartSeriesController;
return SfCartesianChart(
series: <LineSeries<SalesData, num>>[
LineSeries<SalesData, num>(
onRendererCreated: (ChartSeriesController controller) {
_chartSeriesController = controller;
},
onPointTap: (ChartPointDetails args) {
final CartesianChartPoint<dynamic> chartPoint = CartesianChartPoint<dynamic>(
chartData[args.pointIndex!].x,
chartData[args.pointIndex!].y);
final Offset? pointLocation = _chartSeriesController?.pointToPixel(chartPoint);
print('X location: ${pointLocation!.dx}');
print('Y location: ${pointLocation.dy}');
},
),
],
);
}
Implementation
Offset pointToPixel(CartesianChartPoint<dynamic> point) {
return calculatePointToPixel(point, seriesRenderer);
}