pixelToPoint method

ChartPoint pixelToPoint(
  1. Offset position
)

Converts chart data point value to logical pixel value.

The pointToPixel method takes chart data point value as input and returns logical pixel value.

Note: It returns the data point's center location value.

late CircularSeriesController seriesController;
SfCircularChart(
   onChartTouchInteractionDown: (ChartTouchInteractionArgs args) {
    ChartPoint<double> chartPoint =
       seriesController.pixelToPoint(args.position);
    Offset value = seriesController.pointToPixel(chartPoint);
    ChartPoint<double> chartPoint1 = seriesController.pixelToPoint(value);
  },
  series: <PieSeries<SalesData, String>>[
    PieSeries<SalesData, String>(
      onRendererCreated: (CircularSeriesController controller) {
        seriesController = controller;
      }
    )
  ]
)

Converts logical pixel value to the data point value.

The pixelToPoint method takes logical pixel value as input and returns a chart data point.

late CircularSeriesController seriesController;
SfCircularChart(
   onChartTouchInteractionDown: (ChartTouchInteractionArgs args) {
    ChartPoint<double> chartPoint =
      seriesController.pixelToPoint(args.position);
    Offset value = seriesController.pointToPixel(chartPoint);
  },
  series: <PieSeries<SalesData, String>>[
    PieSeries<SalesData, String>(
      onRendererCreated: (CircularSeriesController controller) {
        seriesController = controller;
      }
    )
  ]
)

Implementation

/// Converts logical pixel value to the data point value.
///
/// The [pixelToPoint] method takes logical pixel value as input and
/// returns a chart data point.
///
///```dart
/// late CircularSeriesController seriesController;
/// SfCircularChart(
///    onChartTouchInteractionDown: (ChartTouchInteractionArgs args) {
///     ChartPoint<double> chartPoint =
///       seriesController.pixelToPoint(args.position);
///     Offset value = seriesController.pointToPixel(chartPoint);
///   },
///   series: <PieSeries<SalesData, String>>[
///     PieSeries<SalesData, String>(
///       onRendererCreated: (CircularSeriesController controller) {
///         seriesController = controller;
///       }
///     )
///   ]
/// )
/// ```

ChartPoint pixelToPoint(Offset position) {
  int pointIndex = -1;
  for (int i = 0; i < seriesRenderer.segments.length; i++) {
    final ChartSegment segment = seriesRenderer.segments[i];
    if (segment.contains(position)) {
      pointIndex = i;
    }
  }
  final dynamic x = seriesRenderer.xValues[pointIndex];
  final num y = seriesRenderer.yValues[pointIndex];
  return ChartPoint<D>(x: x, y: y);
}