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"> <s:SciChartSurface Grid.Row="1" Margin="3" x:Name="Chart"
s:ThemeManager.Theme="ExpressionLight">
<s:SciChartSurface.RenderableSeries>
<s:FastLineRenderableSeries SeriesColor="Blue" DataSeries="{Binding Series1.ChartData}" XAxisId="XAxis1" YAxisId="YAxis1"/>
<s:FastLineRenderableSeries SeriesColor="Red" DataSeries="{Binding Series2.ChartData}" XAxisId="XAxis1" YAxisId="YAxis1"/>
</s:SciChartSurface.RenderableSeries>
<s:SciChartSurface.XAxis>
<s:NumericAxis AxisTitle="{Binding Series1.XCaption}" Id="XAxis1" AnimatedVisibleRange="{Binding Series1.XRange, Mode=OneWay}" GrowBy="0.05, 0.05" />
</s:SciChartSurface.XAxis>
<s:SciChartSurface.YAxis>
<s:NumericAxis AxisTitle="{Binding Series1.YCaption}" Id="YAxis1" AnimatedVisibleRange="{Binding Series1.YRange, Mode=OneWay}" GrowBy="0.05, 0.05" />
</s:SciChartSurface.YAxis>
<s:SciChartSurface.ChartModifier>
<s:ModifierGroup>
<s:RubberBandXyZoomModifier IsEnabled="True" IsXAxisOnly="False" ZoomExtentsY="False" IsAnimated="True"/>
<s:MouseWheelZoomModifier />
<s:ZoomPanModifier IsEnabled="True" ExecuteOn="MouseMiddleButton" />
</s:ModifierGroup>
</s:SciChartSurface.ChartModifier>
</s:SciChartSurface></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 = "XAxis1",
YAxisId = "YAxis1",
VerticalAlignment = VerticalAlignment.Stretch,
LabelValue = "Level",
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?
- dan.bryant asked 10 years ago
- You must login to post comments
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
- Yuriy Zadereckiy answered 10 years ago
- You must login to post comments
Please login first to submit.