A CalendarPattern class specifies a pattern such as specific days in a week, months in a year etc. You can specify a time unit of any other time unit to form the pattern. For example: weeks of a year, seconds of a minute, days of a year, even milliseconds of a year.
Calendar patterns can be used with axis markers to highlight parts of a time scale axis and with Series.Trim to trim away elements with time values that land within the calendar pattern. They can also be used to specify a sequence of scale breaks on a time based axis.
The CalendarPattern.PatternFromString method can be used to quickly create patterns using simple string of zeros (0) and ones (1). A week pattern would look like this: "0000000". A zero for each day of the week starting with saturday and ending with sunday. A pattern that flags the weekend (saturday and sunday) would look like this: "1000001".
CalendarPattern myCalendarPattern = new CalendarPattern();
myCalendarPattern.CalendarUnit = TimeInterval.Week;
myCalendarPattern.PatternUnit = TimeInterval.Day;
myCalendarPattern.Pattern = CalendarPattern.FromString("1000001");
Dim myCalendarPattern As CalendarPattern = new CalendarPattern()
myCalendarPattern.CalendarUnit = TimeInterval.Week
myCalendarPattern.PatternUnit = TimeInterval.Day
myCalendarPattern.Pattern = CalendarPattern.FromString("1000001")
In a pattern the __Unit properties refer to a single value (PatternUnit) and the whole pattern (CalendarUnit) like so:
"1000001" <-- CalendarUnit (Week)
PatternUnit of CalendarUnit (Sunday)
The above calendar pattern will flag each saturday and sunday in a given, time span.
If all the values are not provided, the pattern will assume false for the missing values. So if we used "100" for the above pattern, it would be the same as "1000000"
|Calendar Patterns require a time axis scale.|
When a calendar pattern is used in an axis marker, the axis marker must reside on an axis with a time scale. For more information see Elements & Axis scales.
There are two calendarPattern static properties that allow you to initialize an instance of the calendar pattern object quickly. The properties are Weekends and Weekdays.
The following code instantiates a weekend calendarPattern and is the equivalent of the four lines of code shown above.
CalendarPattern myCalendarPattern = CalendarPattern.Weekends;
CalendarPattern myCalendarPattern = CalendarPattern.Weekends
Calendar patterns are drawn on the axis at exact time instances like the start of the day, end of the day, etc. If you use a pattern like the above and your data shows days as columns, the actual x axis time of those columns may also be the start of the day. This results in the columns being centered on the edge of the pattern. The expected behavior would be that the pattern edges fall between the day columns. To remedy this issue you may use the AdjustmentUnit. This will allow you to adjust the calendar pattern to show correctly on the axis. If your columns represent hours the correct adjustment unit would be TimeInterval.Hour.