【问题标题】:OxyPlot get clicked pointOxyPlot 获得点击点
【发布时间】:2015-03-16 01:50:04
【问题描述】:

我正在尝试通过以下方式在散点图上绘制一些圆圈:

<Grid>
    <oxy:PlotView x:Name="PlotView" Title="{Binding Title}" >
        <oxy:PlotView.Axes>
            <oxy:LinearAxis Position="Bottom" Minimum="-30" Maximum="30" IsAxisVisible="False" IsZoomEnabled="False" IsPanEnabled="False" />
            <oxy:LinearAxis Position="Left" Minimum="0" Maximum="35" IsAxisVisible="False" IsZoomEnabled="False" IsPanEnabled="False"/>
        </oxy:PlotView.Axes>
        <oxy:PlotView.Series>
            <oxy:ScatterSeries Height="100" Width="100" ItemsSource="{Binding Points}" MarkerType="Circle" />
        </oxy:PlotView.Series>
    </oxy:PlotView>
</Grid>

我不知道如何启用某种点击处理程序以在用户点击DataPoint 时触发事件。

例子:

用户在 (X, Y) = (0, 5) 处点击 DataPoint,我想触发一个事件,以便我可以处理该点的点击。

OxyPlot 可以做到这一点吗?我目前正在调查Tracker,看看它是否可能是这条路线,但开始没有想法了。

【问题讨论】:

  • 你试过plotView.MouseDown事件吗?
  • 我有。我能够得到鼠标的 x 和 y 位置,但它与实际绘图无关。
  • 这个我没试过,不过InverseTransform是用来把鼠标坐标转换成绘图坐标的。
  • kenny:您可以将其添加为答案,以便我将其标记为正确答案吗?看来这就是我前进所需要的!

标签: c# wpf xaml oxyplot


【解决方案1】:

PlotView 定义了鼠标事件,从中可以获取鼠标坐标,InverseTransform 用于将鼠标坐标转换为绘图坐标。

例子:

var model = new PlotModel { Title = "Test Mouse Events" };

var s1 = new LineSeries();
model.Series.Add(s1);

double x;

s1.MouseDown += (s, e) =>
{
    x = (s as LineSeries).InverseTransform(e.Position).X;
};

【讨论】:

  • 我知道这是一个老问题,但你能提供这个解决方案的例子吗?我正在努力让它发挥作用。
  • 没有任何事件触发我使用这个。
【解决方案2】:

我无法得到公认的答案。左键单击绘图时,MouseDown 处理程序不会接收事件。但是,它会接收右键单击和双击事件。

我的解决方法是在PlotView 上收听PreviewMouseDown

【讨论】:

  • MouseDown 不接收事件,因为您可能有自定义系列并且不覆盖 TrackerHitResult GetNearestPoint(ScreenPoint point, bool interpolate)。我遇到了同样的问题,但是一旦我为该方法添加了一个覆盖以仅返回 InverseTransform - 一切正常。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-29
  • 1970-01-01
  • 1970-01-01
  • 2022-01-21
  • 1970-01-01
相关资源
最近更新 更多