customize X-Axis time axis

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
bdw
Advanced
Posts: 130
Joined: Mon Mar 07, 2005 5:00 am
Location: New Zealand
Contact:

customize X-Axis time axis

Post by bdw » Fri May 10, 2013 3:41 am

Hello,

We have a x-axis set to TDateTime which we set the BottomAxis->DateTimeFormat to "hh:nn" when showing less that 24 hours worth of data.

Is it possible to display at the day change over (i.e. 00:00 label) a different DateTimeFormat rather than hh:nn let say "ddd" or day + month ?

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: customize X-Axis time axis

Post by Yeray » Fri May 10, 2013 9:18 am

Hello,

You could use the OnGetAxisLabel. However, once you are in this event, you don't know the value for the current label. You already have the formatted label.
So you could set a DateTimeFormat that allows you to identify both the "ddd" (or the "dd/mm") and the "hh:nn". Here you have an example:

Code: Select all

uses Series, DateUtils, StrUtils;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  Chart1.View3D:=false;

  with Chart1.AddSeries(TPointSeries) as TPointSeries do
  begin
    XValues.DateTime:=true;
    for i:=0 to 60 do
      AddXY(IncHour(Today, i), i);
  end;

  Chart1.Axes.Bottom.DateTimeFormat:='dd/mm hh:nn';
end;

procedure TForm1.Chart1GetAxisLabel(Sender: TChartAxis;
  Series: TChartSeries; ValueIndex: Integer; var LabelText: String);
var p: Integer;
begin
  if Sender = Chart1.Axes.Bottom then
  begin
    p:=AnsiPos(' ', LabelText);
    if AnsiEndsStr('00:00', LabelText) then
      LabelText:=Trim(AnsiLeftStr(LabelText, p))
    else
      LabelText:=Trim(AnsiRightStr(LabelText, p));
  end;
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply