Microsoft 图表控件 - 每当我使用财务公式时,大红色 X(坏)

发布于 2024-08-23 10:05:14 字数 1404 浏览 4 评论 0原文

我从这里的另一篇文章中发现了 Microsoft 的 .Net 图表控件,到目前为止我很喜欢它们。对于需要它的人,这是链接: http://code.msdn.microsoft.com/mschart

我在运行时执行所有操作,例如创建系列并将它们放在图表区域上。我可以成功创建一个烛台图,通过为其提供一个 X 值和 4 个 Y 值,当我将它添加到图表中时,如下所示:

// "Price" is the .Name property of this series
chart1.Series.Add(priceseries);

效果很好。接下来,我仔细研究了带有这个可爱的财务公式控件的示例。该示例说使用移动平均公式(仅以此为例,我无法让它们中的任何一个起作用),代码是这样的:

chart1.DataManipulator.FinancialFormula(FinancialFormula.MovingAverage,"5","Input","Simple");

其中“5”是要使用的周期,因此可以是我的任何内容想。 “输入”似乎是数据源系列,“简单”是输出系列。为了将其转变为适合我的代码的方式,我创建了一个按钮并执行了以下操作:

    private void button1_Click(object sender, EventArgs e)
    {
        chart1.DataManipulator.FinancialFormula(FinancialFormula.MovingAverage, "5", "Price", "SMA");     
    }

很好又简单,是吗?好吧,一旦我单击该按钮,我的图表控件就会以任何方式、形状或形式在图表上显示一个大的、红色的、不高兴的 X,而不是移动平均线系列(我将其命名为“SMA”)。

添加到上面的代码中,我尝试预先创建“SMA”系列,我尝试在执行财务公式调用后将“SMA”系列添加到图表中,并且最终都以大平均红色 X 结束。再次查看示例代码,看起来单行代码就足以生成额外的一系列数据,但我被卡住了!红色 X 没有任何调试信息是没有帮助的:(

关于如何摆脱大 X 并让它显示新的数据系列有什么想法吗?

更新: 作为测试,我删除了有关将系列添加到 Chart1 的部分,然后在其后面添加了 Chart1.DataManipulator 位。正如预期的那样,包含我所有初始数据的初始系列没有出现(因为我删除了将其添加到图表中的部分),但是当下一行代码执行公式应用程序时 - 没有大红色 X。没有数据显示,但也没有错误代码 - 所以我想这是一个改进?这让我相信我应用公式的初始数据集存在某种问题,或者与图表控件本身的视图/边界有关。如果我在该轨道上发现更多内容,我会将其作为第二次更新发布。

I discovered Microsoft's .Net charting controls from another post here, and so far I love them. For anyone needing it, here is the link:
http://code.msdn.microsoft.com/mschart

I do everything during runtime, such as creating series and slapping them on a chart area. I can successfully create a Candlestick chart, by supplying it with an X value and 4 Y values, and when I add it to the chart like so:

// "Price" is the .Name property of this series
chart1.Series.Add(priceseries);

It works great. Next, I pored through the samples that came with this lovely control for the financial formulas. The sample says to use the moving average formula (just using this as an example, I can't get any of them to work), the code is this:

chart1.DataManipulator.FinancialFormula(FinancialFormula.MovingAverage,"5","Input","Simple");

Where "5" is the period to use, so that can be whatever I want. "Input" is the data source series it seems, and "Simple" is the output series. To spin this into a way that works with my code, I created a button and did this:

    private void button1_Click(object sender, EventArgs e)
    {
        chart1.DataManipulator.FinancialFormula(FinancialFormula.MovingAverage, "5", "Price", "SMA");     
    }

Nice and simple, ya? Well, as soon as I click that button, my chart control displays a big, red, unhappy X and NOT the moving average series (which I named "SMA") on the chart in any way, shape, or form.

Adding to the above code, I have tried pre-creating the "SMA" series, I have tried adding the "SMA" series to the chart after doing the financialformula call, and both end up with the big mean red X. Going through the sample code again, it appears that the single line of code is all that is needed to generate the extra series of data, but I'm stuck! It doesn't help that the red X has no debugging info whatsoever :(

Any ideas on how to get rid of the big X, and have it display the new series of data instead?

Update:
Just as a test, I removed the bit about adding the series to Chart1, then I added the chart1.DataManipulator bit right after it. As expected, the initial series that has all my initial data doesn't appear (because I removed the part adding it to the chart), but when the next line of code does the formula application - no big red X. There is no data shown, but no error code either - so I guess that is an improvement? This is leading me to believe that there is some sort of problem with either the initial dataset I'm applying the formula to, or something having to do with the view/boundaries of the chart control itself. If I find anything more on that track, I will post it as a second update.

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

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

发布评论

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

评论(3

拥有 2024-08-30 10:05:14

我发现了问题的根源:

priceseries.IsXValueIndexed = true;

我最初这样做是为了忽略任何空白数据点(这将是股票价格场景中的周末)。当我将值更改为 false 时,突然间该公式的应用就正常了。缺点是周末约会有空白,没有数据!但这是另一个我可以自己解决的问题。

对于遇到此问题的其他人,请参阅此参考文章以获取更多信息:
http://msdn.microsoft.com/en-us /library/dd456699(VS.100).aspx

关于首先对数据进行分组的注释可不是开玩笑。不要遗漏任何数据点!

I discovered the source of my problem:

priceseries.IsXValueIndexed = true;

I did this initially to omit any blank data points (which would be the weekends in a stock price scenario). When I changed the value to false, all of a sudden the application of the formula worked fine. The downside is that I have blank spots for weekend dates where there is no data! But that is another issue I can work through on my own.

For anyone else having this issue, see this reference article for additional information:
http://msdn.microsoft.com/en-us/library/dd456699(VS.100).aspx

The note about grouping your data first is no joke. Do not omit any data points!

只是我以为 2024-08-30 10:05:14

我也发生过。

使用 FinancialFormulas(特别是 FinancialFormula.ExponentialMovingAverage)时,系列 ChartType 应设置为 SeriesChartType.Line。

在我的代码中,它被设置为 SeriesChartType.FastLine,这从 System.Drawing.dll 抛出 OverflowException

Happened to me too.

While using FinancialFormulas (FinancialFormula.ExponentialMovingAverage in particular) series ChartType should be set to SeriesChartType.Line.

In my code it was set to SeriesChartType.FastLine and this was throwing OverflowException from System.Drawing.dll

桃扇骨 2024-08-30 10:05:14

大红色X是在运行/解释公式时遇到问题而放弃的控件。也许该公式对于图表控件来说过于复杂和难以处理......也许,有一个更新版本的代码已经解除了限制。 codeplex.com 上肯定有相关内容。

这种情况在设计时也可能发生,当设计一个表单时,将一个控件拖到它上面,在这里和那里设置一些属性,然后得到一个大的红色 X,当控件在设计时行为不当时,这种情况很常见还。

希望这有帮助,
此致,
汤姆.

The big red X is the control that encountered a problem in running/interpreting the formula and gave up the ghost. Perhaps the formula was too complex and wieldy for the Chart control to handle it...Maybe, there's a more up-to-date version of the code that has lifted the restriction. There's bound to be something on codeplex.com for this.

This can happen equally at design time also, when designing a form, and a control is dragged on to it, a few properties set here and there and to get a big red X, this was a common occurrence when a control misbehaves at design time also.

Hope this helps,
Best regards,
Tom.

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