Improvements to Charting

Feb 9, 2011 at 1:04 PM


I made two small additions to the Charting component; maybe they're of use to someone.

1. Between (re-)initialization of my chart and the point where data binding kicked in properly, the date axis on my chart was filled with 365 lines and a label for every day of the current year. I changed the code to initialize to one day, so it looks cleaner during this time. In DateTimeAxis.cs, in the ctor and in OverrideDataRange, replace

int year = DateTime.Now.Year;
this.ActualRange = new Range<IComparable>(new DateTime(year, 1, 1), new DateTime(year + 1, 1, 1));


DateTime today = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
this.ActualRange = new Range<IComparable>(today, today.AddDays(1));

2. I'm changing the IntervalType on my DateTimeAxis, but by default the internal implementation could override the IntervalType in the internal size calculations. The last two lines in CalculateActualInterval are
ActualIntervalType = intervalType;
return interval;
Replace them with
if (IntervalType > intervalType)
Interval = 1;
ActualIntervalType = IntervalType;
return Interval.Value;
ActualIntervalType = intervalType;
return interval;