NHitTestResults and ChartElement.DataPoint No Longer Works


https://www.nevron.com/Forum/Topic12794.aspx
Print Topic | Close Window

By James Richason - 5 Years Ago
We have an old method that used to search for a DataPoint and then display that position on the chart.  DataPoint is no longer found.  Has something changed about how data points are added.

Here's the code:

  private void OnValueChanged(object sender, EventArgs e)
   {
    var xAxisValue = DateTime.FromOADate(_chartHorizontalAxisCursor.Value);
    double yAxisValue = _chartVerticalAxisCursor.Value;
    NHitTestResult hitTest = _chartControl.HitTest(_mouseXPoint, _mouseYPoint);
    if (hitTest.ChartElement == ChartElement.DataPoint)
    {
      if (GetChartCategory(_resultsViewInfo.ChartType) == ChartCategory.Column)
      {
       toolTip1.SetToolTip(_chartControl, "Y:" + yAxisValue.ToString("N"));
      }
      else
      {
       toolTip1.SetToolTip(_chartControl, "X:" + xAxisValue.ToString("MMM dd hh:mm:ss tt") + ", Y:" + yAxisValue.ToString("N"));
      }
    }
    else
    {
      //toolTip1.SetToolTip(_chartControl, "JR");
      toolTip1.SetToolTip(_chartControl, "Y:" + yAxisValue.ToString("N"));
    }
   }


By Nevron Support - 5 Years Ago
Hi James,
We just tested with the following code:
  private void Form1_Load(object sender, EventArgs e)
   {
    NChart chart = nChartControl1.Charts[0];
    chart.Enable3D = true;
    NPointSeries point = new NPointSeries();

    for (int i = 0; i < 10; i++)
    {
      point.Values.Add(i);
    }

    chart.Series.Add(point);

    nChartControl1.MouseMove += NChartControl1_MouseMove;
   }

   private void NChartControl1_MouseMove(object sender, MouseEventArgs e)
   {
    NHitTestResult result = nChartControl1.HitTest(e.X, e.Y);

    if (result.ChartElement == ChartElement.DataPoint)
    {
      textBox1.Text = "Data point: " + result.DataPointIndex.ToString();
    }
    else
    {
      textBox1.Text = result.ChartElement.ToString();
    }
   }

and hit testing was working properly - is there something specific about your configuration - like - 2D/3D, type of series etc...