SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and iOS Chart & 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

Hi Guys,

Can you please help me with the following functionality?
I have got a context menu attached to the SciChartSurface and one of the items is to add an annotation(as it is shown in the image attached). So, the idea is that when I open the menu and select the “Add annotation” It will pick up the nearest point in the chart related to where the click was done and then it will add the annotation to the chart as it is shown in the image attached.
I have already figured out with reading some of the question in this forum, to get the mouse points and the nearest Y point in the series related to that mouse click… like this:

private void AddAnnotationOnClick(object sender, RoutedEventArgs e)
{
// Hit tests are done per renderable series, so get a renderable series
// or iterate over all RenderableSeries
var renderableSeries = SciChartSurface.RenderableSeries[0];

        // Perform the hit test relative to the GridLinesPanel
        var hitTest = renderableSeries.HitTest(MousePoint);

        SciChartSurface.Annotations.Add(new CustomAnnotation { DataContext = hitTest.YValue });
    }


    private Point MousePoint { get; set; }

    private void OnMouseUp(object sender, MouseButtonEventArgs e)
    {
        MousePoint = e.GetPosition(SciChartSurface.GridLinesPanel as UIElement);
    }

As it can be noticed, I have already two annotations that are fix, they are always displayed…

Sorry for my terrible English… hope you guys get the idea…

Thanks very much. 🙂

Images
  • You must to post comments
0
0

Hello there,

You just need to set CustomAnnotation.X1 and Y1 to the HitTest XValue and YValue. Debug these values to see if they are what you expect. Also there are a lot of other properties on HitTestInfo struct which may be useful to you!

In order to set the alignment of the CustomAnnotation, please take a look at this reference article which discusses the VerticalAnchorPoint and HorizontalAnchorPoint properties on annotations.

Let me know if this helps,
Andrew

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.