OxyPlot找到所选的LineSeries

时间:2017-01-26 16:50:36

标签: selection oxyplot lineseries

我有PlotModel多个LineSeries画。 我正在寻找的是选择由MouseDown事件检测到的点所属的所有LineSeries的技巧。

我做到了这一点:

this.MouseDown += CheckIfLineSeriesHasBeenSelected;

private void CheckIfLineSeriesHasBeenSelected(object sender, OxyMouseDownEventArgs e)
{
     switch (e.ChangedButton)
     {
          case OxyMouseButton.Left:
               var series = (LineSeries) this.GetSeriesFromPoint(e.Position, 10);
               series.StrokeThickness = 4;
           break;
      }
 }

但通过这种方式,模型仅改变了整个LineSeries的一小部分的厚度。 你有什么建议吗? 谢谢!

1 个答案:

答案 0 :(得分:0)

您可以在e.Position周围随机搜索并选择系列:

    private void PlotModel_MouseDown(object sender, OxyMouseDownEventArgs e)
    {
        int radius = 5;
        List<LineSeries> ss = new List<LineSeries>();
        searchAndAdd(ref ss, e.Position);
        Random rand = new Random();
        for (int i = 0; i < 100; i++)
        {
            double x = rand.Next(-radius, radius);
            double y = rand.Next(-radius, radius);
            ScreenPoint pos = new ScreenPoint(e.Position.X + x, e.Position.X);
            searchAndAdd(ref ss, pos);
        }
        foreach (var s in ss)
            s.StrokeThickness = 8;
        plotModel.InvalidatePlot(false);
    }
    void searchAndAdd(ref List<LineSeries> series, ScreenPoint pos)
    {
        var s = plotModel.GetSeriesFromPoint(pos, 10) as LineSeries;
        if (s != null && series.Contains(s) == false)
            series.Add(s);
    }

请注意radius确定您要搜索的距离。另请注意,您最后应致电plotModel.InvalidatePlot(false);