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

2

6

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

Edit - And how do I set the XAxis max scale

myPane.XAxis.Type = AxisType.Date;
myPane.XAxis.Scale.Min = 0;
myPane.XAxis.Scale.Max = 12;
Equiponderance answered 4/2, 2009 at 18:25 Comment(0)
C
5

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

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

Here is an example of a chart using the XDate structs

Cavesson answered 4/2, 2009 at 18:36 Comment(0)
A
11

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.

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):

pane.XAxis.Type = AxisType.Date;
pane.XAxis.Scale.MajorUnit = DateUnit.Hour;
pane.XAxis.Scale.Format = "T";
Anglim answered 3/2, 2011 at 10:6 Comment(0)
C
5

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

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

Here is an example of a chart using the XDate structs

Cavesson answered 4/2, 2009 at 18:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.