.NET Chart:如何添加具有不同于 double 的成员类型的 DataPoint?
我正在查看的命名空间是 .NET Framework 3.5 中的 System.Windows.Forms.DataVisualization.Charting。
我构建了一个名为 chart1
的 Chart
,并向该图表添加了一个名为 mySeries
的 Series
。
在设计器中该系列的数据部分中,我有:
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 DataPoint
s 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
DateTime.ToOADate() 将返回时间戳作为双精度值,可用作 x 值
DateTime.ToOADate() will return the timestamp as a double that can be used as x value
DataPoint
不接受 x 和 y 的其他类型。您需要使用datum.TimeStamp.Ticks
进行排序/排序,然后设置AxisLabel
属性 (string
) 以显示 <代码>日期时间。DataPoint
doesn't accept other types for x and y. You'll need to usedatum.TimeStamp.Ticks
for ordering/sorting, and then set theAxisLabel
property (string
) to display theDateTime
.