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

0
0

I have an application where I’m attempting to add annotations from the code-behind. My chart XAML looks like this:

   <pre class="brush: xml; gutter: true; first-line: 1; highlight: []; html-script: false"> &lt;s:SciChartSurface Grid.Row=&quot;1&quot; Margin=&quot;3&quot; x:Name=&quot;Chart&quot;
                       s:ThemeManager.Theme=&quot;ExpressionLight&quot;&gt;
        &lt;s:SciChartSurface.RenderableSeries&gt;
            &lt;s:FastLineRenderableSeries SeriesColor=&quot;Blue&quot; DataSeries=&quot;{Binding Series1.ChartData}&quot; XAxisId=&quot;XAxis1&quot; YAxisId=&quot;YAxis1&quot;/&gt;
            &lt;s:FastLineRenderableSeries SeriesColor=&quot;Red&quot; DataSeries=&quot;{Binding Series2.ChartData}&quot; XAxisId=&quot;XAxis1&quot; YAxisId=&quot;YAxis1&quot;/&gt;
        &lt;/s:SciChartSurface.RenderableSeries&gt;

        &lt;s:SciChartSurface.XAxis&gt;
            &lt;s:NumericAxis AxisTitle=&quot;{Binding Series1.XCaption}&quot; Id=&quot;XAxis1&quot; AnimatedVisibleRange=&quot;{Binding Series1.XRange, Mode=OneWay}&quot; GrowBy=&quot;0.05, 0.05&quot; /&gt;
        &lt;/s:SciChartSurface.XAxis&gt;

        &lt;s:SciChartSurface.YAxis&gt;
            &lt;s:NumericAxis AxisTitle=&quot;{Binding Series1.YCaption}&quot; Id=&quot;YAxis1&quot; AnimatedVisibleRange=&quot;{Binding Series1.YRange, Mode=OneWay}&quot; GrowBy=&quot;0.05, 0.05&quot; /&gt;
        &lt;/s:SciChartSurface.YAxis&gt;

        &lt;s:SciChartSurface.ChartModifier&gt;
            &lt;s:ModifierGroup&gt;
                &lt;s:RubberBandXyZoomModifier  IsEnabled=&quot;True&quot; IsXAxisOnly=&quot;False&quot; ZoomExtentsY=&quot;False&quot; IsAnimated=&quot;True&quot;/&gt;
                &lt;s:MouseWheelZoomModifier /&gt;
                &lt;s:ZoomPanModifier IsEnabled=&quot;True&quot; ExecuteOn=&quot;MouseMiddleButton&quot; /&gt;
            &lt;/s:ModifierGroup&gt;
        &lt;/s:SciChartSurface.ChartModifier&gt;
    &lt;/s:SciChartSurface&gt;</pre>

I’m trying to add a vertical line annotation like this:

            <pre class="brush: csharp; gutter: true; first-line: 1; highlight: []; html-script: false">var line = new VerticalLineAnnotation
            {
                X1 = 85,
                Y1 = 0,
                XAxisId = &quot;XAxis1&quot;,
                YAxisId = &quot;YAxis1&quot;,
                VerticalAlignment = VerticalAlignment.Stretch,
                LabelValue = &quot;Level&quot;,
                ShowLabel = true,
                LabelPlacement = LabelPlacement.Axis,
                Stroke = new SolidColorBrush(Colors.DeepSkyBlue)
            };
            Chart.Annotations.Add(line);  </pre>              

Unfortunately the annotation is not appearing. Everything else seems to work fine, including the data, axis ranges and modifiers. If I create the annotation manually in XAML, it works fine. Am I missing a step in my code-behind to make the annotation display properly?

  • You must to post comments
0
0

Hi,

Your code looks alright at first sight. Try removing YAxisId and Y1 coordinate setting as it requires setup for X coord only. Also, please, take a look at this thread, where an example of annotations added in code was shown.

If the above doesn’t help, could I ask you to make a small sample project which reproduces the issue and post here/send it to us?

Best regards,
Yuriy

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.