zoukankan      html  css  js  c++  java
  • Winform中设置ZedGraph鼠标悬浮显示举例最近曲线上的点的坐标值和X轴与Y轴的标题

    场景

    Winform中设置ZedGraph鼠标双击获取距离最近曲线上的点的坐标值:

    https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/102466406

    现在要实现鼠标悬浮时显示距离最近曲线上的点的横纵坐标和X轴和Y轴的标题。

    注:

    博客主页:
    https://blog.csdn.net/badao_liumang_qizhi
    关注公众号
    霸道的程序猿
    获取编程相关电子书、教程推送与免费下载。

    实现

    在包含ZedGraph控件的窗体的load方法中执行初始化zedGraph的方法,在初始化的方法中对鼠标悬浮事件重新绑定。

    zgc.CursorValueEvent -= zgc_CursorValueEvent;       //显示焦点值事件
    zgc.CursorValueEvent += zgc_CursorValueEvent;       //显示焦点值事件

    然后在显示焦点值事件中

    private static string zgc_CursorValueEvent(ZedGraphControl sender, GraphPane pane, Point mousePt)
            {
                //获取ZedGraphControl对象
                ZedGraphControl zgc = sender as ZedGraphControl;
                if (zgc != null)
                {
                    //声明曲线对象
                    CurveItem nearstCurve;
                    int i;
                    Double y = 0.0;
                    string z = String.Empty;
                    string xTitle = String.Empty;
                    string yTtile = String.Empty;
                    try
                    {
                        //获取距离最近的曲线
                        zgc.GraphPane.FindNearestPoint(mousePt, out nearstCurve, out i);
                        if (nearstCurve != null && nearstCurve.Points.Count > i && nearstCurve.Points[i] != null)
                        {
                            //获取举例最近的点的Tag,在生成曲线时使用Tag存储的X轴的信息
                            z = nearstCurve.Points[i].Tag.ToString();
                            //获取当前pane面板的XAxis的标题的文本内容
                            xTitle = zgc.GraphPane.XAxis.Title.Text;
                            //获取当前pane面板的YAxis的标题的文本内容,通过nearstCurve.YAxisIndex获取当前举例最近的曲线所对应的Y轴的Index
                            yTtile = zgc.GraphPane.YAxisList[nearstCurve.YAxisIndex].Title.Text;
                            y = nearstCurve.Points[i].Y;
                        }
                    }
                    catch(Exception ex)
                    {
    
                    }
                    return "X-" + xTitle + ": " + z + "  Y-" + yTtile +": "+ y.ToString();
                }
                else
                {
                    return String.Empty;
                }
            } 
  • 相关阅读:
    关于用户流量运营相关方面
    郑州房市
    公众号运营
    面试知识点总结
    Ubuntu根目录下各文件夹的功能详细介绍(轉)
    ubuntu 使用印象筆記 evernote nixnote2
    安装ktorrent amule 下载edk2 迅雷文件
    i2p
    ubuntu开启ipv6
    tg-bot备忘
  • 原文地址:https://www.cnblogs.com/badaoliumangqizhi/p/11888899.html
Copyright © 2011-2022 走看看