[英].NET Chart: How to add DataPoint with different member types than double?
我正在查看的命名空间是.NET Framework 3.5中的System.Windows.Forms.DataVisualization.Charting
。
我已经构建了Chart
名称为chart1
并增加了一个Series
叫mySeries
该排行榜。
在设计师的该系列的数据部分中,我有:
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.