3

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);
}
Community
  • 1
  • 1
DarwinIcesurfer
  • 1,073
  • 4
  • 25
  • 42

1 Answers1

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.

LeoD3
  • 195
  • 10
Quantbuff
  • 827
  • 7
  • 9
  • 1
    I believe the e.PostBackValue.Split should split using the "," delimiter and not the semi-colon ";" delimiter. Probably just a typo, but pointing it out for anyone who stumbles upon this question. – CodeFu65816 Oct 14 '13 at 17:22