1

I'm trying to retrieve the series name from a mouse-click event in a Chart. I've looked through the documentation, including HitTestResult Class, from which I've gathered that I should be able to get the series using HitTestResult.Series.

When I try this, I get "An object reference is required for the non-static field, ..." error. While I understand (albeit a cursory understanding) what this error is referring to, mostly from responses to questions of other folks here on stackoverflow, I'm at a loss as to what's going on in my code.

Note: When I'm typing "HitTestResult.", Series is not an option in the IntelliSense; instead the only two options are Equals and ReferenceEquals.

Any thoughts or insights are appreciated. Thanks!!

Sample code:

private void myChart_MouseClick(object sender, MouseEventArgs e)
 {
   HitTestResult seriesHit = myChart.HitTest(e.X, e.Y);
    if (seriesHit.ChartElementType == ChartElementType.DataPoint)
    {
      MessageBox.Show("Selected by Series!");
      // ^^ This, as a test box, works fine...
      parameterNameStr = HitTestResult.Series.Name;
      // ^^ This is what I want but is causing trouble!
 }
   else if (seriesHit.ChartElementType == ChartElementType.LegendItem)
    {
      MessageBox.Show("Selected by Legend!!");
    }
   else
    {
      MessageBox.Show("Whoops, try again!");
    }
 }  
4

1 に答える 1

3

愚かな私。私はただそこにいて、ただ何も考えていなかった...

うまくいったのは次のとおりです。

[...]
   parameterNameStr = seriesHit.Series.Name;
                    // ^^^^^ Simple fix!!
[...]
于 2013-09-04T19:20:13.983 に答える