Reputation: 43
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>
Upvotes: 3
Views: 685
Reputation: 863
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;
}
}
}
Upvotes: 2