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 ?
customize X-Axis time axis
Re: customize X-Axis time axis
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:
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,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |