winform中实现Oxyplot.WindowsForms.Plot的鼠标悬停坐标值展示

界面增加Oxyplot.WindowsForms.Plot,鼠标悬停显示坐标值。

PlotType = PlotType.XY          

private void InitPlotModel()
{
    this.plot.Model = _PlotModel;
    this.plot.Enabled = true;

    this.plot.MouseHover += PlotView_MouseHover;

    this.plot.MouseHover += PlotView_MouseLeave;
}

//增加光标悬停显示坐标值
private System.Windows.Forms.ToolTip toolTip =  new System.Windows.Forms.ToolTip();
public Oxyplot.WindowsForms.Plot plot = null;
private void PlotView_MouseHover(object sender, EventArgs e)
{
    toolTip = new System.Windows.Forms.ToolTip();
    var plotView = ((Oxyplot.WindowsForms.Plot)sender).Model;
   
    // 获取鼠标在PlotView控件中的坐标位置
    var mousePosition = ((Oxyplot.WindowsForms.Plot)sender).PointToClient(Cursor.Position);

    // 将鼠标位置的屏幕坐标转换为数据点的坐标值
    var xAxis = plotView.Axes[0];
    var yAxis = plotView.Axes[1];
    double x = xAxis.InverseTransform(mousePosition.X, mousePosition.Y, yAxis).X;

    //修改数值的展示
    double y = xAxis.InverseTransform(mousePosition.X, mousePosition.Y, yAxis).Y;

    // 在ToolTip中显示数据点的数值信息
    toolTip.SetToolTip(((Oxyplot.WindowsForms.Plot)sender), $"{xAxis.Title}: {x},{yAxis.Title}: {y}");

    // 设置ToolTip的AutoPopDelay属性为3000毫秒(3秒)
    toolTip.AutoPopDelay = 3000;
}


private void PlotView_MouseLeave(object sender, EventArgs e)
{
    if( plot != null)
    {
        toolTip.RemoveAll();
    }
}

  • 8
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值