The database has 3 fields with dates. This means 3 segments. To x1, from x1 to x2, from x2 to x2 + x days. And the segment of the chart itself is usually 24 hours, i.e. y1 and y1 + 23:59:59, where y1, for example, 03/10/12. I work with time in Unix format, i.e. seconds.
The complexity itself is to deduce from the database the fields that fall within the conditions of this chart. For example:
10.03.12 00:00|---------------------------------------------|10.03.12 23:59:59
And in the database
05.03.12 10:00, 10.03.12 12:00, 10.03.12 11:00
i.e our time span falls into range. The central date does not take sense, but only the extreme parts of the range.
How to set the withdrawal condition? There is actually a couple of comparisons, but it is necessary that even if 1 hour falls, then output. Or half-band, for example:
10.03.12 00:00|---------------------------------------------|10.03.12 23:59:59
And in the database
10.03.12 23:00, 12.03.12 12:00, 15.03.12 11:00
those. The first date for the hour, but falls into our schedule.
PS The beginning and end of the segment should also be taken into account, because the schedule can be either a day or a week, and you will have to output data that at least falls into the graph, for example:
10.03.12 00:00|---------------------------------------------|17.03.12 23:59:59
And in the database
11.03.12 10:00, 12.03.12 12:00, 13.03.12 11:00
They were completely hit, but only an hour of the schedule at the beginning or an hour at the end could.
The function of drawing graphics colors is and displays in increments of an hour.