C# ZedGraph - 我正在寻找使用 DateTime 的示例

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/512642/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 06:18:14  来源:igfitidea点击:

ZedGraph - I am looking for an example of using a DateTime

c#zedgraph

提问by Brad

I am looking for an example of using a datetime field on a zedgraph linechart X-Axis.

我正在寻找在 zedgraph 折线图 X 轴上使用日期时间字段的示例。

Edit - And how do I set the XAxis max scale

编辑 - 我如何设置 XAxis 最大比例

myPane.XAxis.Type = AxisType.Date;
myPane.XAxis.Scale.Min = 0;
myPane.XAxis.Scale.Max = 12;

采纳答案by scottm

You will have to convert the DateTime variables to XDatestructs. You can create a method like this:

您必须将 DateTime 变量转换为XDate结构。您可以创建这样的方法:

public XDate ConvertDateToXdate(DateTime date)
{
  return new XDate(date.ToOADate);
}

Here is an exampleof a chart using the XDate structs

这是使用 XDate 结构的图表示例

回答by cmroanirgo

Having had the same problem recently, I discovered that the above answer isn't actually correct. The sample code simple casts an XDate() to a double.

最近遇到了同样的问题,我发现上面的答案实际上并不正确。示例代码 simple 将 XDate() 转换为 double。

However, the sample does highlight what you need to do. I still use DateTime.ToOADate(), but with the addition of the following code, I get to see times (in HH:MM:SS format):

但是,该示例确实突出了您需要执行的操作。我仍然使用 DateTime.ToOADate(),但是通过添加以下代码,我可以看到时间(以 HH:MM:SS 格式):

pane.XAxis.Type = AxisType.Date;
pane.XAxis.Scale.MajorUnit = DateUnit.Hour;
pane.XAxis.Scale.Format = "T";