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

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy. We also have a tag=SciChart on Stackoverflow.com where you can earn rep for your questions!

Please note: SciChart team will only answer questions from customers with active support subscriptions. Expired support questions will be ignored. If your support status shows incorrectly, contact us and we will be glad to help.

0
0

Hello all,
I have a candle-chart with the following x-Axis:

<s:SciStockChart.XAxisStyle>
    <Style TargetType="s:CategoryDateTimeAxis">
        <Setter Property="BarTimeFrame" Value="{Binding BarTimeFrame, Mode=OneWay}"/>
        <Setter Property="DrawMinorGridLines" Value="False"/>
        <Setter Property="DrawMajorBands" Value="True"/>
        <Setter Property="VisibleRange" Value="{Binding XVisibleRange, Mode=TwoWay}"/>
        <Setter Property="DrawMinorGridLines" Value="False"/>
        <Setter Property="AutoRange" Value="{Binding AutoRange, Mode=TwoWay}" />
        <Setter Property="GrowBy" Value="0, 0.1"/>
    </Style>
</s:SciStockChart.XAxisStyle>

I want to add a vertical line at a specific date:

VerticalLineAnnotation newVerticalLine = new VerticalLineAnnotation();
newVerticalLine.X1 = ((DateTime)pAnnotationAttributes.GetValue(GUI_AnnotationAttributes.TimeValue)).;

Doing this I get the following exception:
Ein Ausnahmefehler des Typs “System.InvalidCastException” ist in mscorlib.dll aufgetreten.
Zusätzliche Informationen: Invalid cast from ‘DateTime’ to ‘Int32’.

Regards

Michael

  • You must to post comments
1
0

Hi there,

If your XAxis is CategoryDateTimeAxis, then any annotation.X1 value requires an integer.

This is the index to the DataSeries.XValues as category axis uses Index, not Date to measure on the X-Axis.

Please try it and let me know if this helps,

Best regards,
Andrew

  • You must to post comments
0
0

thanks, how can I transform the DateTime to the appropriate int value?

Regards

Michael

  • You must to post comments
0
0

I found it myself 🙂

VerticalLineAnnotation newVerticalLine = new VerticalLineAnnotation();
int index = CandleChart.RenderableSeries[0].DataSeries.FindIndex(yourDateTimeValue, SearchMode.Nearest);
newVerticalLine.X1 = index;

Regards

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.