OxyPlot WPF - 获取选定的列

时间:2016-01-27 10:41:02

标签: c# wpf oxyplot

我正在尝试在OxyPlot WPF中选择(单击)列。有没有办法做到这一点?到目前为止我的WPF代码:

    <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>

1 个答案:

答案 0 :(得分:2)

没有选定的列属性。您需要在列系列上实现mousedown事件,并使用GetNearestPoint()函数确定单击了哪个列。

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;
         }
    }
}