繁体   English   中英

.NET Chart:如何使用不同于double的成员类型添加DataPoint?

[英].NET Chart: How to add DataPoint with different member types than double?

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

我已经构建了Chart名称为chart1并增加了一个SeriesmySeries该排行榜。

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

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

当我尝试将DataPoint添加到这样的系列时,似乎我无法使用相应类型的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);         
    }
}

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM