showByIndex method
Displays the crosshair at the specified point index.
pointIndex - index of point at which the crosshair needs to be shown.
Implementation
void showByIndex(int pointIndex) {
// ignore: unnecessary_null_comparison
if (_stateProperties != null) {
final CrosshairBehaviorRenderer crosshairBehaviorRenderer =
_stateProperties.crosshairBehaviorRenderer;
final CrosshairRenderingDetails renderingDetails =
CrosshairHelper.getRenderingDetails(crosshairBehaviorRenderer);
if (validIndex(pointIndex, 0, renderingDetails.crosshairPainter!.chart)) {
if (renderingDetails.crosshairPainter != null) {
final List<CartesianSeriesRenderer> visibleSeriesRenderer =
renderingDetails.crosshairPainter!.stateProperties.chartSeries
.visibleSeriesRenderers;
final SeriesRendererDetails seriesRendererDetails =
SeriesHelper.getSeriesRendererDetails(visibleSeriesRenderer[0]);
final List<CartesianChartPoint<dynamic>> dataPoints =
getSampledData(seriesRendererDetails);
// ignore: unnecessary_null_comparison
if (pointIndex != null &&
pointIndex.abs() < seriesRendererDetails.dataPoints.length) {
renderingDetails.crosshairPainter!.generateAllPoints(Offset(
dataPoints[pointIndex].markerPoint!.x,
dataPoints[pointIndex].markerPoint!.y));
}
renderingDetails.crosshairPainter!.canResetPath = false;
renderingDetails.crosshairPainter!.stateProperties
.repaintNotifiers['crosshair']!.value++;
}
}
}
}