Microsoft.NET图表组件在股票图表上创建简单移动平均线

本文关键字:移动 简单 创建 组件 NET Microsoft | 更新日期: 2023-09-27 18:29:53

我正在创建一个简单的Microsoft Forms应用程序,该应用程序将使用Microsoft.Net图表控件库显示股票图表。我可以使用LINQ to SQL:成功显示股票操作

IEnumerable<Quote> quotes = Store.Quotes.Where(q => q.Ticker == "MSFT" && q.Date > DateTime.Parse("7/01/2013"));
MainChart.Series["SeriesTop"].Points.Clear();
MainChart.Series["SeriesTop"].Points.DataBindXY(quotes, "Date", quotes, "Low,High,Open,Close");
MainChart.Series["SeriesTop"].LegendText = quotes.First().Ticker;

然而,如果我加上一个简单移动平均线,我会得到一个大的红色X,而不是图表,没有例外或其他消息会有所帮助。这是破坏它的代码行:

MainChart.DataManipulator.FinancialFormula(FinancialFormula.MovingAverage, "5", "SeriesTop", "AvgTop");

我使用visualstudio来检查"AvgTop"系列的内容,它在我看来还可以,但图表不会显示。

谢谢,Ken

Microsoft.NET图表组件在股票图表上创建简单移动平均线

我玩过DataManipulator.InsertEmptyPoints(根据http://msdn.microsoft.com/en-us/library/dd456677.aspx)红色的大X消失了,但周末充满了空数据,我不希望这样,我希望周末(和其他非交易日)从图表中消失(见Series.IsXValueIndexed = true)。因此,我推出了自己的方法来对齐两个数据系列:

    public static void AlignSeries(Series seriesA, Series seriesB)
    {
        var aligned = seriesA.Points.GroupJoin(seriesB.Points, a => a.XValue, b => b.XValue, (a, b) => new { a = a, b = b.SingleOrDefault() }).ToArray();
        DataPointCollection bCollection = seriesB.Points;
        bCollection.Clear();
        foreach (var pair in aligned)
        {
            DataPoint bPoint = new DataPoint();
            bPoint.XValue = pair.a.XValue;
            if (null != pair.b)
            {
                bPoint.YValues = pair.b.YValues;
            }
            else
            {
                bPoint.IsEmpty = true;
            }
            bCollection.Add(bPoint);
        }
    }

我当然希望比我更有智慧的人能推荐一种更好的方法或我错过的API调用。