When attaching a TextAnnotation to the last data point of a Line Series, the annotation may disappear if the user scrolls or zooms the chart such that the final data point moves outside the visible Plot Rect. This makes it difficult for users to identify series data when only a portion of the line is visible on screen.
Solution
To ensure the annotation remains visible, you can dynamically update its position by handling the Rendering event of the FlexChart. Within this event, you should compare the location of your annotation (or the last data point) against the current maximum value of the AxisX.
If the data point's X-coordinate exceeds the current AxisX.Max, you can programmatically reposition the annotation to stay within the visible bounds (for example, by setting its X-location to AxisX.Max minus a small offset). If the point is within the visible range, the annotation should revert to its original position at the end of the series. This approach ensures that the label "clings" to the edge of the plot area as long as the line itself is still partially visible.
private void FlexChart_Rendering(object sender, C1.WPF.Chart.RenderEventArgs e)
{
if (chart.AxisX.Max < textAnnotation.Location.X)
{
textAnnotation.Location = new Point(chart.AxisX.Max - 12, textAnnotation.Location.Y);
}
else
{
textAnnotation.Location = (series1.ItemsSource as PointCollection).Last();
}
}
private void Hide_LastIndex(object sender, RoutedEventArgs e)
{
chart.AxisX.Max = 140;
}
private void Show_LastIndex(object sender, RoutedEventArgs e)
{
chart.AxisX.Max = 200;
}