3

我正在查看的命名空间System.Windows.Forms.DataVisualization.Charting位于 .NET Framework 3.5 中。

我已经构建了一个Chart带有名称的名称并向该图表chart1添加了一个Series调用。mySeries

在设计器中该系列的数据部分中,我有:

IsXValueIndexed --> False
Name --> mySeries
Points --> (Collection)
XValueType --> DateTime
YValuesPerPoint --> 1
YValueType --> Int32

当我尝试DataPoint像这样将 s 添加到系列时,似乎我无法使用适当类型的 x 和 y 值添加它们:

public void InitializeChart()
{
    Series theSeries = chart1.Series["mySeries"];

    // MyData is of type List<MyDatum> and MyDatum has two members --
    //    one of type DateTime and another of type int

    foreach (MyDatum datum in MyData)
    {
        // I'd like to construct a DataPoint with the appropriate types,
        //    but the compiler wants me to supply doubles to dp

        DataPoint dp = new DataPoint(mySeries);
        dp.XValue = datum.TimeStamp;
        dp.YValue = datum.MyInteger;

        radiosConnectedSeries.Points.Add(dp);         
    }
}

我错过了什么?一如既往的感谢!

4

2 回答 2

4

DateTime.ToOADate() 将时间戳作为可用作 x 值的双精度值返回

于 2011-04-22T00:42:33.530 回答
2

DataPoint不接受 x 和 y 的其他类型。您需要datum.TimeStamp.Ticks用于排序/排序,然后设置AxisLabel属性 ( string) 以显示DateTime.

于 2011-04-22T00:07:01.827 回答