欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 产业 > C#中鼠标点击获取Chart图形上的坐标值

C#中鼠标点击获取Chart图形上的坐标值

2025/5/11 4:52:01 来源:https://blog.csdn.net/wlpz0528/article/details/144925895  浏览:    关键词:C#中鼠标点击获取Chart图形上的坐标值

/// <summary>/// C#中鼠标移动获取Chart图形上的坐标值/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void chart1_GetToolTipText(object sender, System.Windows.Forms.DataVisualization.Charting.ToolTipEventArgs e){if (e.HitTestResult.ChartElementType == ChartElementType.DataPoint){this.Cursor = Cursors.Cross;int i = e.HitTestResult.PointIndex;System.Text.StringBuilder dpStr = new System.Text.StringBuilder();foreach (var item in chart1.Series){DataPoint dp = item.Points[i];dpStr.Append(item.Name + " X:" + dp.XValue + " Y:" + dp.YValues[0] + "\r\n");}e.Text = dpStr.ToString();}else{this.Cursor = Cursors.Default;}}

=========================================================================

 

this.chart1.MouseClick += new MouseEventHandler(chart1_MouseClick);

/// <summary>/// C#中鼠标点击获取Chart图形上的坐标值/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void chart1_MouseClick(object sender, MouseEventArgs e){// 获取点击位置的点的坐标HitTestResult result = chart1.HitTest(e.X, e.Y);if (result.ChartElementType == ChartElementType.DataPoint){int index = result.PointIndex;DataPoint point = chart1.Series[0].Points[index];double xValue = point.XValue;double yValue = point.YValues[0];MessageBox.Show($"Clicked at: X = {xValue}, Y = {yValue}");}}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词