当前位置: 移动技术网 > IT编程>开发语言>.net > Winform(C#)中Chart控件鼠标点击显示波形上相应点对应坐标轴的x,y值

Winform(C#)中Chart控件鼠标点击显示波形上相应点对应坐标轴的x,y值

2019年09月01日  | 移动技术网IT编程  | 我要评论

什锦锉规格,陆小凤传奇之海兰花,莱雅娜的坠饰

方法一:鼠标点击波形

鼠标点击波形,显示点击位置的x,y值

private void chart1_mouseclick(object sender, mouseeventargs e)  //chart1是你建的chart控件,实际名字根据你自己代码里的命名
        {            
            hittestresult hit = chart1.hittest(e.x, e.y);
            if (hit.series != null)
            {
                var xvalue = hit.series.points[hit.pointindex].xvalue;
                var yvalue = hit.series.points[hit.pointindex].yvalues.first();
                textbox1.text = string.format("{0:f0},{1:f0}", "x:"+xvalue, "y:"+yvalue);//textbox1也是自己建的一个专门用来显示的内容框,也可以用messagebox直接弹出内容
            }
            else
            {
                textbox1.text="未点击到波形曲线";
            }
        }

 

调用方法:

chart1.mouseclick += new mouseeventhandler(chart1_mouseclick);

 

方法二:鼠标移动到相应点位自动显示相关数值

private void chart1_mousemove(object sender, mouseeventargs e)
        {
            var area = chart1.chartareas[0];

            double xvalue = area.axisx.pixelpositiontovalue(e.x);
            double yvalue = area.axisy.pixelpositiontovalue(e.y);
            textbox1.text = string.format("{0:f0},{1:f0}", xvalue, yvalue);
        }

调用方法:

chart1.mousemove += new mouseeventhandler(chart1_mousemove);

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网