Page 1 of 1
customize X-Axis time axis
Posted: Fri May 10, 2013 3:41 am
by 9236183
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 ?
Re: customize X-Axis time axis
Posted: Fri May 10, 2013 9:18 am
by yeray
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;