3

I'm using MS Chart with C# and I'm having issues when I try to retrieve almost any meta values from the chart, all I am getting is NaN. Couple of examples...

void chart_CursorPositionChanged(object sender, CursorEventArgs e)
{
            double selectStart = e.NewSelectionStart;
            double selectEnd = e.NewSelectionEnd;
}

e.NewSelectionStart and e.NewSelectionEnd both show NaN for their values.

Another example...

chart.ChartAreas[0].AxisX.Maximum

is also NaN. However, if I set it to a value the chart properly reflects it. Any ideas what I'm doing wrong?

spender
  • 117,338
  • 33
  • 229
  • 351
Motie Mediator
  • 268
  • 1
  • 3
  • 9

2 Answers2

1

It sounds like you might not be properly initializing chart.ChartAreas[0]: Have you set Cursor.IsUserSelectionEnabled to true?

chart.ChartAreas[0].CursorX.IsSelectionEnabled = true;

If you haven't enabled user selecting then the event will still fire when a user clicks and moves the mouse, but a selection won't take place.

As for

chart.ChartAreas[0].AxisX.Maximum == Double.NaN

This means that the chart will manage the margin itself.

Guildencrantz
  • 1,875
  • 1
  • 16
  • 30
0

Instead of using the data provided by CursorEventArgs like you currently are, do this:

void chart_CursorPositionChanged(object sender, CursorEventArgs e)
{
            double selectStart = chart.ChartAreas["ChartArea1"].CursorX.SelectionStart;
            double selectEnd = chart.ChartAreas["ChartArea1"].CursorX.SelectionEnd;

}

I experienced the same problem as you today, and this solved it for me. I dont know why the CursorEventArg data returns an NaN though

7VoltCrayon
  • 662
  • 1
  • 7
  • 22