2

I want to change the scale of X-axis. X-axis is of type Date

myPane.XAxis.Scale.Min = 
myPane.XAxis.Scale.Max =

I want the Min to be start of a particular month and Max to be end of the same month

ie

myPane.XAxis.Scale.Min = ***1/3/2011;***
myPane.XAxis.Scale.Max=***31/3/2011;***

I should be able to give in different month programmatically; how do I do can anyone help?

Cœur
  • 37,241
  • 25
  • 195
  • 267
pdthekd
  • 87
  • 1
  • 1
  • 11

1 Answers1

0

In ZedGraph, dates and time values are handled by the XDate object.

So you have to do this way:

myPane.XAxis.Scale.Min = new XDate(new DateTime(2011, 3, 1));
myPane.XAxis.Scale.Max = new XDate(new DateTime(2011, 3, 31));

Because you want the user to enter a month value, here is a solution:

var year = 2011;
var month = 10;

myPane.XAxis.Scale.Min = new XDate(new DateTime(year, month, 1));
myPane.XAxis.Scale.Max = new XDate(new DateTime(year, month, DateTime.DayInMonth(year , month)));

Then it will work with months that counts 30 or 31 days, including february that counts 28 and 29 at leap years.

Larry
  • 17,605
  • 9
  • 77
  • 106
  • Remark for future readers: The DateTime object can also be converted using the `.ToOADate()` method instead of using the `XDate` constructor. – Andreas Duering Jun 14 '17 at 15:23