【问题标题】:OxyPlot WPF - Get slected columnOxyPlot WPF - 获取选定的列
【发布时间】:2016-01-27 23:57:20
【问题描述】:

我正在尝试在 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>

【问题讨论】:

    标签: c# wpf oxyplot


    【解决方案1】:

    没有选定的列属性。您需要在列系列上实现 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;
             }
        }
    }
    

    【讨论】:

    • 我的事件参数有问题 - ColumnSeries_MouseDown(object sender, MouseButtonEventArgs e)。 MoseButtonEventArgs != OxyMouseDownEventArgs
    • OxyPlot 版本:
    • 在这种情况下,您可以尝试使用 ConverterExtensions.ToMouseDownEventArgs(this MouseButtonEventArgs e, IInputElement relativeTo)。这会将 MouseButtonEventArgs 转换为 OxyMouseDownEventArgs
    • 我设法获得了鼠标参数,但 OxyPlot.Wpf.ColumnSeries 对象上没有 GetNearestPoint 方法:(
    猜你喜欢
    • 1970-01-01
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-13
    • 1970-01-01
    • 1970-01-01
    • 2015-06-05
    相关资源
    最近更新 更多