简体   繁体   中英

OxyPlot WPF - Get slected column

I am trying to get selected (clicked) column in OxyPlot WPF. Is there any way to do that? My WPF code so far:

    <oxy:Plot x:Name="plotDiagram" Title="Output" >
        <oxy:Plot.Axes>
            <oxy:CategoryAxis ItemsSource="{Binding Item.barDisplayData1}" LabelField="DisplayText"/>
            <oxy:LinearAxis MinimumPadding="0" AbsoluteMinimum="0"/>
        </oxy:Plot.Axes>
        <oxy:Plot.Series>
            <oxy:ColumnSeries Title="{Binding Item.Title1}" FillColor="Green" IsStacked="True" ItemsSource="{Binding Item.barDisplayData1}" ValueField="Value" />
            <oxy:ColumnSeries Title="{Binding Item.Title2}" FillColor="Red" IsStacked="True" ItemsSource="{Binding Item.barDisplayData2}" ValueField="Value"/>
            <oxy:ColumnSeries Title="{Binding Item.Title3}" FillColor="Yellow" IsStacked="True" ItemsSource="{Binding Item.barDisplayData3}" ValueField="Value"/>
        </oxy:Plot.Series>
    </oxy:Plot>

There is no selected column property. You need to implement the mousedown event on the column series and determine which column was clicked using the GetNearestPoint() function.

void columns_MouseDown(object sender, MouseButtonEventArgs e)  
{         
    var cols = sender as ColumnSeries;    
     OxyMouseDownEventArgs args = ConverterExtensions.ToMouseDownEventArgs(e, sender);
    if (cols != null)      
    {         
         TrackerHitResult nearestPoint = cols.GetNearestPoint(args.Position, false);           
         if(nearestPoint != null) {
            object selectedColumn = nearestPoint.Item;
         }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM