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


I have a real time charting program that is getting data from accel sensors. When the sampling is complete, I allow them to add annotations to the graph. I also have the double-click ZoomExtentsModifier active, which normally works great. I added a text annotation but when I double-click it doesn’t include the text annotation in the extents and as a result the text is not showing on the screen. Is there something I am doing wrong? I don’t want the user to get confused when the text isn’t visible. I allow them to save and re-load so on the re-load the text doesn’t show unless the user zooms out.

  • You must to post comments

Hi Richard,

The ZoomExtentsModifier zooms to fit the chart to the available series. ZoomExtents does not take into account annotations in the viewport, only series.

The best workaround is to override the ViewportManager to include the Annotations in the viewport on Zoom Extents.

To do this I’ve used the ViewportManager feature and code as follows:

public class ViewportManagerWithAnnotations : DefaultViewportManager
    private ISciChartSurface _parentSurface;

    public override void AttachSciChartSurface(ISciChartSurface scs)
        _parentSurface = scs;


    protected override IRange OnCalculateNewXRange(IAxis xAxis)
        var xAxisRange = base.OnCalculateNewXRange(xAxis);
        return MergeRanges(xAxis, xAxisRange);

    protected override IRange OnCalculateNewYRange(IAxis yAxis, RenderPassInfo renderPassInfo)
        var yAxisRange = base.OnCalculateNewYRange(yAxis, renderPassInfo);
        return MergeRanges(yAxis, yAxisRange);

    private IRange MergeRanges(IAxis axis, IRange axisRange)
        // Get the autorange for the annotations
        var annotationsRange = CalculateAutoRangeForAnnotations(axis);

        // merge with the axis range 
        if (annotationsRange.IsDefined)
            axisRange = axisRange.Union(annotationsRange);
            axisRange = axisRange.GrowBy(axis.GrowBy.Min.ToDouble(), axis.GrowBy.Max.ToDouble());

        return axisRange;

    private IRange CalculateAutoRangeForAnnotations(IAxis axis)
        double min = double.MaxValue;
        double max = double.MinValue;

        // loop through annoations
        foreach (var annotation in _parentSurface.Annotations)
            // is this annoation registered on this axis 
            bool axisMatch = (axis.IsXAxis && annotation.XAxisId == axis.Id) ||
                             (!axis.IsXAxis && annotation.YAxisId == axis.Id);

            if (axisMatch)
                // Accumulate the min, max X1/Y1
                min = Math.Min((axis.IsXAxis ? annotation.X1 : annotation.Y1).ToDouble(), min);
                max = Math.Max((axis.IsXAxis ? annotation.X1 : annotation.Y1).ToDouble(), max);

                // For annotations that have two points
                if (!(annotation is AnchorPointAnnotation))
                    // Accumulate the min, max X2/Y2
                    min = Math.Min((axis.IsXAxis ? annotation.X2 : annotation.Y2).ToDouble(), min);
                    max = Math.Max((axis.IsXAxis ? annotation.X2 : annotation.Y2).ToDouble(), max);

        return new DoubleRange(min, max);

and in the View

            <s:NumericAxis GrowBy="0.1, 0.1"/>
            <s:NumericAxis GrowBy="0.1, 0.1"/>

            <s:TextAnnotation Text="Hi there!" X1="-5" Y1="11" HorizontalAnchorPoint="Center" VerticalAlignment="Center" />
            <s:TextAnnotation Text="Here are some annotations" X1="5" Y1="5" HorizontalAnchorPoint="Center" VerticalAlignment="Center" />
            <s:TextAnnotation Text="Included in AutoRange!" X1="15" Y1="-2" HorizontalAnchorPoint="Center" VerticalAlignment="Center" />


This results in AutoRange considering the annotation positions.

Let me know if this helps,

Best regards,

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.