MS 图表和 NaN

发布于 2024-08-22 02:57:32 字数 473 浏览 6 评论 0原文

我正在使用带有 C# 的 MS Chart,当我尝试从图表中检索几乎所有元值时遇到问题,我得到的只是 NaN。几个例子...

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.

另一个例子...

chart.ChartAreas[0].AxisX.Maximum

也是 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 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北恋 2024-08-29 02:57:32

听起来您可能没有正确初始化 chart.ChartAreas[0]:您是否将 Cursor.IsUserSelectionEnabled 设置为 true?

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

如果您尚未启用用户选择,则当用户单击并移动鼠标时,该事件仍会触发,但不会发生选择。

这意味着

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

图表将自行管理保证金。

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.

终陌 2024-08-29 02:57:32

不要像您当前那样使用 CursorEventArgs 提供的数据,而是执行以下操作:

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

}

我今天遇到了与您相同的问题,这为我解决了它。我不知道为什么 CursorEventArg 数据返回 NaN

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文