欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ZedGraph的曲线的LineItem对象的Tag属性存储信息进而在鼠标悬浮时进行显示

程序员文章站 2023-10-28 18:21:10
场景 Winform中设置ZedGraph鼠标悬浮显示距离最近曲线上的点的坐标值和X轴与Y轴的标题: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/103140781 上面博客能实现鼠标悬浮显示最近的曲线上点的坐标值与X轴和Y轴的 ......

场景

winform中设置zedgraph鼠标悬浮显示距离最近曲线上的点的坐标值和x轴与y轴的标题:

https://blog.csdn.net/badao_liumang_qizhi/article/details/103140781

上面博客能实现鼠标悬浮显示最近的曲线上点的坐标值与x轴和y轴的标题,

如果想要再显示其他信息,比如曲线所对应的文件名等。

那么就要在生成曲线时将自定义要保存的信息与曲线进行绑定存储。

注:

博客主页:

关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。

实现

zedgraph的曲线对象是lineitem,其有一属性tag可以用它来存储额外信息。

在生成曲线时

lineitem mycurve = mypane.addcurve(ylist[i].title, list, system.drawing.colortranslator.fromhtml(ylist[i].color), symboltype);
//使用曲线tag存储数据库名 文件名
//文件完整路径
string filepath = comptestdatalist[k].thisdatafile;
//文件名
 string filename = system.io.path.getfilenamewithoutextension(filepath);
//数据库名
string dbname = system.io.directory.getparent(filepath).tostring();
dbname = dbname.substring(dbname.lastindexof('\\') + 1);
dbname = "db_" + dbname;
//短文件名
string[] titles = filename.split('_');
string shortfilename = "柜" + titles[titles.length - 2] + "通道" + titles[titles.length - 1];
mycurve.tag = dbname + shortfilename;
mycurve.yaxisindex = i;

 

生成曲线时使用曲线对象的tag属性存储了自定义的一些信息。

那么在鼠标的悬浮事件中

tag = nearstcurve.tag.tostring();

完整示例代码

private static string zgc_cursorvalueevent(zedgraphcontrol sender, graphpane pane, point mousept)
        {
            zedgraphcontrol zgc = sender as zedgraphcontrol;
            if (zgc != null)
            {
                curveitem nearstcurve;
                int i;
                double x = 0.0;
                double y = 0.0;
                string xtitle = string.empty;
                string yttile = string.empty;
                string tag = string.empty;
                string xvlaue = string.empty;
                string z = string.empty;
                try
                {
                    zgc.graphpane.findnearestpoint(mousept, out nearstcurve, out i);
                    if (nearstcurve != null && nearstcurve.points.count > i && nearstcurve.points[i] != null)
                    {
                        z = nearstcurve.points[i].tag.tostring();
                        y = nearstcurve.points[i].y;
                        xtitle = zgc.graphpane.xaxis.title.text;
                        //获取当前pane面板的yaxis的标题的文本内容,通过nearstcurve.yaxisindex获取当前距离最近的曲线所对应的y轴的index
                        yttile = zgc.graphpane.yaxislist[nearstcurve.yaxisindex].title.text;
                        tag = nearstcurve.tag.tostring();
                    }
                }
                catch (exception ex)
                {

                }
                return tag+ " x-" + xtitle + ": " + z + "  y-" + yttile + ": " + y.tostring();
            }
            else
            {
                return string.empty;
            }
        }

效果

ZedGraph的曲线的LineItem对象的Tag属性存储信息进而在鼠标悬浮时进行显示

 

 

ZedGraph的曲线的LineItem对象的Tag属性存储信息进而在鼠标悬浮时进行显示