How can I select a specific point in a LineSeries

1.2k views Asked by At

I'm currently trying to select a point in a lineSeries using toolkit in a wpf application. I'm just trying to select it using a mouse event but I'm on it for hours and haven't had any success so far.

Here is an extract of my xaml

<Grid Name="amplitude_envelope" Grid.ColumnSpan="9" Grid.Column="2" Grid.Row="6" Margin="0,0,95,0">
            <chartingToolkit:Chart Title="Amplitude Envelope" Name="chart1"  AllowDrop="True" >

                <chartingToolkit:Chart.Series>

                    <chartingToolkit:LineSeries 
                        Name="my_line"
                        MouseDown="StartDrag"
                        MouseLeave="StopDrag"
                        MouseMove="DragObject"
                        IsSelectionEnabled="True"
                        Title="Envelope"
                        DependentValuePath="Power" IndependentValuePath="Speed" >
                        <chartingToolkit:LineSeries.DependentRangeAxis>
                            <chartingToolkit:LinearAxis
                                    Orientation="Y"
                                    Title="Amplitude (%)"
                                    Minimum="0"
                                    Maximum="1.2"
                                    Interval="0.2"
                                    ShowGridLines="True"/>
                        </chartingToolkit:LineSeries.DependentRangeAxis>
                    </chartingToolkit:LineSeries>
                </chartingToolkit:Chart.Series>

            </chartingToolkit:Chart>
        </Grid>

and my DragObject method looks like:

private void DragObject(object sender, MouseEventArgs e)
    {
        if (my_line.IsMouseCaptured)
        {
            LineSeries line = (LineSeries)sender;
            var dp = line.SelectedItem;
        }
    }

I just don't find what I should do in order to call my StartDrag event when cliking directly on a point (So far I can do It when clicking on the line or the chart... but that's not what I'm looking for)

Do you have some idea for me?

1

There are 1 answers

0
Hunter Hsieh On

You can define your events in LineSeries.DataPointStyle:

<chartingToolkit:LineSeries.DataPointStyle>
    <Style>
        <EventSetter Event="Control.MouseDown" Handler="StartDrag"/>          
    </Style>
</chartingToolkit:LineSeries.DataPointStyle>

Also, remember to set IsSelectionEnabled to False.

Reference: Adding events on WPF LineSeries DataPoint