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

发布于 2024-11-02 22:55:01 字数 1117 浏览 5 评论 0原文

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

我构建了一个名为 chart1Chart,并向该图表添加了一个名为 mySeriesSeries

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

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);         
    }
}

我缺少什么?一如既往的感谢!

The namespace I'm looking at is System.Windows.Forms.DataVisualization.Charting in .NET Framework 3.5.

I've constructed a Chart with name chart1 and added a Series called mySeries to that chart.

Within the Data section of that series in the designer, I have:

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

When I try to add DataPoints to the series like this, it seems like I cannot add them with the x and y values of the appropriate type:

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);         
    }
}

What am I missing? Thanks as always!

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

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

发布评论

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

评论(2

反目相谮 2024-11-09 22:55:01

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

DateTime.ToOADate() will return the timestamp as a double that can be used as x value

土豪我们做朋友吧 2024-11-09 22:55:01

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

DataPoint doesn't accept other types for x and y. You'll need to use datum.TimeStamp.Ticks for ordering/sorting, and then set the AxisLabel property (string) to display the DateTime.

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