[英]OxyPlot find the selected LineSeries
我有一個PlotModel
有多個LineSeries
的PlotModel
。 我正在尋找一個技巧,以選擇該點所屬的所有LineSeries,該點由MouseDown
事件檢測。
我已經做到了:
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的一小部分的厚度。 你有什么建議嗎? 謝謝!
您可以在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);
在末尾。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.