showByIndex method
Displays the tooltip at the specified series and point index.
-
seriesIndex - index of the series for which the pointIndex is specified
-
pointIndex - index of the point for which the tooltip should be shown
Implementation
void showByIndex(int seriesIndex, int pointIndex) {
final dynamic chartState = _chartState;
final dynamic chart = chartState._chart;
final TooltipBehaviorRenderer tooltipBehaviorRenderer =
_chartState._tooltipBehaviorRenderer;
dynamic x, y;
if (chart is SfCartesianChart) {
if (_validIndex(pointIndex, seriesIndex, chart)) {
final CartesianSeriesRenderer cSeriesRenderer =
_chartState._chartSeries.visibleSeriesRenderers[seriesIndex];
if (cSeriesRenderer._visible!) {
x = cSeriesRenderer._dataPoints[pointIndex].markerPoint!.x;
y = cSeriesRenderer._dataPoints[pointIndex].markerPoint!.y;
}
}
if (x != null && y != null && chart.series[seriesIndex].enableTooltip) {
if (chart.tooltipBehavior.builder != null) {
tooltipBehaviorRenderer._showTemplateTooltip(Offset(x, y));
} else if (chart.series[seriesIndex].enableTooltip) {
tooltipBehaviorRenderer._showTooltip(x, y);
}
}
} else if (chart is SfCircularChart) {
if (chart.tooltipBehavior.builder != null &&
seriesIndex < chart.series.length &&
pointIndex <
_chartState._chartSeries.visibleSeriesRenderers[seriesIndex]
._dataPoints.length &&
chart.series[seriesIndex].enableTooltip) {
//to show the tooltip template when the provided indices are valid
_chartState._circularArea
._showCircularTooltipTemplate(seriesIndex, pointIndex);
} else if (chart.tooltipBehavior.builder == null &&
chartState._animationCompleted == true &&
pointIndex >= 0 &&
(pointIndex + 1 <=
_chartState._chartSeries.visibleSeriesRenderers[seriesIndex]
._renderPoints.length)) {
final ChartPoint<dynamic> chartPoint = _chartState._chartSeries
.visibleSeriesRenderers[seriesIndex]._renderPoints[pointIndex];
if (chartPoint.isVisible) {
final Offset position = _degreeToPoint(
chartPoint.midAngle!,
(chartPoint.innerRadius! + chartPoint.outerRadius!) / 2,
chartPoint.center!);
x = position.dx;
y = position.dy;
tooltipBehaviorRenderer._showTooltip(x, y);
}
}
} else if (pointIndex != null && // ignore: unnecessary_null_comparison
pointIndex <
_chartState
._chartSeries.visibleSeriesRenderers[0]._dataPoints.length) {
//this shows the tooltip for triangular type of charts (funnerl and pyramid)
if (chart.tooltipBehavior.builder == null) {
_chartState._tooltipPointIndex = pointIndex;
final Offset? position = _chartState._chartSeries
.visibleSeriesRenderers[0]._dataPoints[pointIndex].region?.center;
x = position?.dx;
y = position?.dy;
tooltipBehaviorRenderer._showTooltip(x, y);
} else {
if (chart is SfFunnelChart && chartState._animationCompleted == true) {
_chartState._funnelplotArea._showFunnelTooltipTemplate(pointIndex);
} else if (chart is SfPyramidChart &&
chartState._animationCompleted == true) {
_chartState._chartPlotArea._showPyramidTooltipTemplate(pointIndex);
}
}
}
tooltipBehaviorRenderer._isInteraction = false;
}