How to display irregular date/time labels.


If a handler is attached to the OnDrawDateLabel event, it is called repeatedly to return the date/time of each label in turn. For this example, we'll label the first day of each month (although the ChartAppearance.DateTimeFormat property could be set to "MMM" so that only the month name would be shown.)

  procedure TForm1.RACDrawDateLabel(Sender: TObject;
                                    var DateTime: TDateTime);
  var
    y, m, d: word;
    dt: TDateTime;
  begin
    DecodeDate(DateTime, y, m, d);
    // find date of first day of next month
    inc(m);
    if m = 13 then begin
      m := 1;
      inc(y);
    end;
    // add MonthDays div 2 to centre label within the month
    DateTime := EncodeDate(y, m, 1) + MonthDays[IsLeapYear(y), m] div 2;
  end;

Note: This event handler can be invoked many times a second while the user is dragging the chart or an allocation. It is important that it completes quickly in order to maintain a responsive user experience.

What People Say

I did want to drop you a note and tell you what a wonderful component. It's a must have component if you are a serious Delphi developer.
Miguel Henley, Brazil
More …

No malware No spam
McAfee Site Report
Web of Trust