MS Chart and NaN
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 i开发者_StackOverflow中文版s 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?
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.
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
精彩评论