Get Mouse click event from Microsoft Chart Control click on data marker

北城以北 提交于 2020-01-13 05:56:26

问题


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 Showing Mouse Axis Coordinates on Chart Control

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

回答1:


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(',');
    // Add click event code here
}

You need to set OnClick="Chart1_Click" in asp:Chart. Or if you have multiple series on your chart you can set PostBack on Series directly and pass information about the series.



来源:https://stackoverflow.com/questions/9691000/get-mouse-click-event-from-microsoft-chart-control-click-on-data-marker

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!