获取鼠标点击从数据标记Microsoft图表控件单击事件 [英] Get Mouse click event from Microsoft Chart Control click on data marker

查看:160
本文介绍了获取鼠标点击从数据标记Microsoft图表控件单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序的.NET 4.0点图。我想捕捉的数据标记鼠标点击。当用户点击一个特定的点,我喜欢去排在数据来自的绑定表。



时此功能内置到在.NET图表控件



编辑:我发现,我可能其实是想光标位置值,而不是要求用户点击一个特定的数据点。一旦我有光标的位置,该值可以用于发现在最接近鼠标点击数据集中的行。我接受了答案,我原来的问题下面,因为它是一个正确的答案,我的最初要求。



我的'现实'问题的解决方法是在后发现人用户奎因在后
MS图表控件:显示鼠标轴坐标

  {
VAR chartArea = _chart.ChartAreas [0];
VAR xValue = chartArea.AxisX.PixelPositionToValue(X);
变种y值= chartArea.AxisY.PixelPositionToValue(Y);
返回新的记录<双层,双>(xValue,y值);
}


解决方案

您可以试试这个

 保护无效的Page_Load(对象发件人,EventArgs五)
{
的foreach(数据点DP IN this.Chart1。 。系列[YourSeriesName]点)
{
dp.PostBackValue =#VALX,#VALY
}
}
保护无效Chart1_Click(对象发件人,ImageMapEventArgs E)
{
的String [] = pointData e.PostBackValue.Split(';');
}

您需要的图表OnClick事件设置此功能。
或如果你有你的图表可以在系列直接设置回传,并通过对一系列信息上的多个系列。


I have a .net 4.0 point chart in my app. I would like to capture the mouse click on a data marker. When the user clicks on a particular point, I'd like to go to the row in the bound table where the data came from.

Is this functionality built-in to the .net chart control?

EDIT: I found that I may have actually wanted the cursor position value rather than requiring the user to click on a specific data point. Once I have the cursor location, that value can be used to find the row in the dataset that is closest to the mouse click. I accepted the answer to my original question below as it was a correct answer to what I initially requested.

The solution to my 'real' problem was found in the post by user quinn in the post MS Chart Control : Showing Mouse Axis Coordinates

{
    var chartArea = _chart.ChartAreas[0];
    var xValue = chartArea.AxisX.PixelPositionToValue(x);
    var yValue = chartArea.AxisY.PixelPositionToValue(y);
    return new Tuple<double, double>(xValue, yValue);
}

解决方案

You can try this

protected void Page_Load(object sender, EventArgs e)
{
    foreach (DataPoint dp in this.Chart1.Series["YourSeriesName"].Points)
    {
        dp.PostBackValue = "#VALX,#VALY";
    }
}
protected void Chart1_Click(object sender, ImageMapEventArgs e)
{
    string[] pointData = e.PostBackValue.Split(';');    
}

You need to set OnClick event of the chart to this function. Or if you have multiple series on your chart you can set PostBack on Series directly and pass information about the series.

这篇关于获取鼠标点击从数据标记Microsoft图表控件单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆