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

方法一:鼠标点击波形

鼠标点击波形,显示点击位置的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);

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!


版权声明:本文为weixin_30750685原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。