X axis Interval for Hourly type of report
I am having hourly trend report, where i have space for only 15 x axis points. I take start time and end time, diff them and if hours are more than 15 then I divide them with 15 and that how i get the interval value for the chart.
TimeSpan span = customEndTime.Subtract(customStartTime); //This is from a dll
if (span.Hours > 15)
{
double IntervalSpan = (double)span.Hours;
double Interval = IntervalSpan / 15;
return Convert.ToInt16(Math.Ceiling(Interval));
}
This works only when dates are same line.
e.g
Start Date 4/22/2011 00:00:00 AM
End Date 4/22/2011 11:00:00 AM
Interval = 1
My X axis shows points like
4/22/2011 00:00,
4/22/2011 01:00,
4/22/2011 02:00 and so on...
Start
Date 4/22/2011 00:00:00 AM End Date 4/22/2011 11:00:00 PM
Interval = 2
My X axis shows points like
4/22/2011 00:00,
4/22/2011 02:00,
4/22/2011 04:00 and so on...
But
when i have two dates like Start Time 4/22/2011 00:00:00 AM and End Time 4/23/2011 10:00:00 AM
The
interval logic dosent work and i see congested 34 points, where I want only less than 15 points no matter what is start date and end date.
Can you point me the error or any suggestion ?
April 29th, 2011 7:28am
Hi Akshay_Jadhav,
After read the description thoroughly, I think we need to use span.TotalHours Property provided by TimeSpan instead of span.Hours. The reason is that span.Hours only represent the hour difference between the two time (00:00:00 - 10:00:00) rather than
the two datetime.
Therefore, for Start Time 4/22/2011 00:00:00 AM and End Time 4/23/2011 10:00:00 AM, it has 1 day (24 hours) and 10 hours difference. span.Hours equals to 10 hours, and it is less than 15 that you mentioned.
To work on this, please check follows, (NOTE: I use .TotalHours instead, in that case, if condition will be fit, and the interval will be 3)
TimeSpan span = customEndTime.Subtract(customStartTime);
if (span.TotalHours > 15)
{
double IntervalSpan = (double)span.TotalHours;
double Interval = IntervalSpan / 15;
return Convert.ToInt16(Math.Ceiling(Interval));
}
For more details, please look at the article:
http://msdn.microsoft.com/en-us/library/system.timespan(v=vs.80).aspx
If you have any question, please ask. Thanks.
Eileen.
Free Windows Admin Tool Kit Click here and download it now
May 2nd, 2011 11:31am
Hi Akshay_Jadhav,
After read the description thoroughly, I think we need to use span.TotalHours Property provided by TimeSpan instead of span.Hours. The reason is that span.Hours only represent the hour difference between the two time (00:00:00 - 10:00:00) rather than
the two datetime.
Therefore, for Start Time 4/22/2011 00:00:00 AM and End Time 4/23/2011 10:00:00 AM, it has 1 day (24 hours) and 10 hours difference. span.Hours equals to 10 hours, and it is less than 15 that you mentioned.
To work on this, please check follows, (NOTE: I use .TotalHours instead, in that case, if condition will be fit, and the interval will be 3)
TimeSpan span = customEndTime.Subtract(customStartTime);
if (span.TotalHours > 15)
{
double IntervalSpan = (double)span.TotalHours;
double Interval = IntervalSpan / 15;
return Convert.ToInt16(Math.Ceiling(Interval));
}
For more details, please look at the article:
http://msdn.microsoft.com/en-us/library/system.timespan(v=vs.80).aspx
If you have any question, please ask. Thanks.
Eileen.
May 2nd, 2011 11:31am
Thanks !! It worked :)
Free Windows Admin Tool Kit Click here and download it now
May 3rd, 2011 6:29am