Search code examples
dynamic-data-display

draw vertical line with D3 ( Dynamic Data Display)


I am creating a ChartPlotter and using CursorCoordinateGraph i am able to get the X coordinate on MouseLeftButtonDown event.

    private CursorCoordinateGraph mouseTrack;
    private void OnLoaded(object sender, RoutedEventArgs e)
    {
        mouseTrack = new CursorCoordinateGraph();
        firstPlotter.Children.Add(mouseTrack);
    }


    private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        Point mousePos = mouseTrack.Position;
        var transform = firstPlotter.Viewport.Transform;
        Point mousePosInData = mousePos.ScreenToData(transform);
        double xValue = mousePosInData.X;
    }

Is there a way to draw a vertical line on that xValue coordinate? I am a bit lost in line graphs, lines, vertical lines..


Solution

  • Add this lines of code after the computation of xValue in OnMouseLeftButtonDown.

    VerticalLine vl = new VerticalLine();
    vl.Value = xValue;
    

    I assume you want to add that line to the aforementioned plottter:

    firstPlotter.Children.Add(vl);
    

    You can use the same approach for HorizontalLine.