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.
Note: This method is only applicable for cartesian chart, not for the circular, pyramid, and funnel charts.
Widget build(BuildContext context) {
ChartSeriesController seriesController;
return Container(
child: SfCartesianChart(
series: <CartesianSeries<ChartSampleData, num>>[
ColumnSeries<ChartSampleData, num>(
onRendererCreated: (ChartSeriesController controller) {
seriesController = controller;
},
)
],
onPointTapped: (PointTapArgs args) {
CartesianChartPoint<dynamic> chartPoint =
CartesianChartPoint<dynamic>(data[args.pointIndex].x,
data[args.pointIndex].y);
Offset pointLocation = seriesController.pointToPixel(chartPoint);
print('X location: ${pointLocation.x}');
print('Y location: ${pointLocation.y}');
},
)
);
}
Implementation
Offset pointToPixel(CartesianChartPoint<dynamic> point) {
final num x = point.x;
final num y = point.y;
final ChartAxisRenderer xAxisRenderer = seriesRenderer._xAxisRenderer!;
final ChartAxisRenderer yAxisRenderer = seriesRenderer._yAxisRenderer!;
final bool isInverted = seriesRenderer._chartState!._requireInvertedAxis;
final CartesianSeries<dynamic, dynamic> series = seriesRenderer._series;
final _ChartLocation location = _calculatePoint(
x,
y,
xAxisRenderer,
yAxisRenderer,
isInverted,
series,
seriesRenderer._chartState!._chartAxis._axisClipRect);
return Offset(location.x, location.y);
}