0

我创建了一个简单的 Microsoft Forms 应用程序,它将使用 Microsoft .Net Chart Controls Library 显示股票图表。我可以使用 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");

我使用 Visual Studio 检查“AvgTop”系列的内容,它看起来不错,但图表不会显示。

谢谢,肯

4

1 回答 1

1

我玩过 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 调用。

于 2013-09-02T02:58:27.703 回答