SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and iOS Chart & Android Chart Components

0
0

I created a CustomRenderableSeries to put TextAnnotations on surface for every drawn point.

I discovered that Draw method is not called when no points are to be drawn in the visible range, so i can’t do any cleanup of the annotations i created in a previous pass.

Is there a way to force Draw method to be called anyway upon surface redraw (for example when zooming)?

Thank you

Version
6.0.0.12976
  • You must to post comments
0
0

Here is my piece of code so you can see how i’m handling the drawing

        protected override void Draw(IRenderContext2D renderContext, IRenderPassData renderPassData)
    {
        base.Draw(renderContext, renderPassData);

        foreach (var a in track.Surface.Annotations.ToList())
        {
            Surface.Annotations.Remove(a);
        }

        // The data for this render pass
        var dataPointSeries = renderPassData.PointSeries as Point2DSeries;

        if (dataPointSeries == null || dataPointSeries.Count == 0) return;

        var xCalc = renderPassData.XCoordinateCalculator;

        // Iterate over the point series
        for (int i = 0; i < dataPointSeries.Count; i++)
        {
            // Get the X value
            var x = dataPointSeries.XValues[i];

            // Transform coordinate
            var xCoord = xCalc.GetCoordinate(x);
            if (xCoord >= 0 && xCoord < renderContext.ViewportSize.Height)
            {
                double yCoord = 0;

                var text = <get text from x value>

                var TextAnnotation = new TextAnnotation();
                TextAnnotation.CoordinateMode = AnnotationCoordinateMode.Relative;
                TextAnnotation.VerticalAnchorPoint = VerticalAnchorPoint.Top;
                TextAnnotation.X1 = xCoord / renderContext.ViewportSize.Height;
                TextAnnotation.Y1 = yCoord;
                TextAnnotation.Text = text;
                Surface.Annotations.Add(TextAnnotation);
            }
        }
    }

Surface is the current drawn surface.
This solution works well except when the method is not called because of empty data series or no points in the visibile range. In this case the annotations stay on the surface while they should be removed.

  • You must to post comments
0
0

Can you explain your solution with a small piece of code?
I can’t understand your approach.

Thank you

  • You must to post comments
0
0

This is by design unfortunately, RenderableSeries will not be drawn unless they have a DataSeries and data in it. That data must also be on-screen.

However you just said that you want to display text for every drawn point. So why not pass the data for every drawn point to the CustomRenderableSeries and use that data to position your text?

Best regards,
Andrew

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.