Hi,
I am looking to have time on a x axis I have tried datetime, but some data goes past 24 hrs which adds to the day and i would like to display as hours. 25:15:35 instead of 01:15:35. Is there anyway to do this with datetime or a custom label?
Any help would be appreciated
Thanks,
Paul
time on x-axis
Re: time on x-axis
Hello,
You could intercept the labels at OnGetAxisLabel event and modify them to fit your needs.
You could intercept the labels at OnGetAxisLabel event and modify them to fit your needs.
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
-
- Newbie
- Posts: 2
- Joined: Mon Jun 10, 2019 12:00 am
Re: time on x-axis
Thank you for your response, but I am unclear as to how to change the labels as each time it updates it changes the labels back to the original. Also the only useful parameter I see in the function is the label which is a string and not the value it represents. If you could clear any of this up for me it would be much appreciated.
Thank you,
Paul
Thank you,
Paul
Re: time on x-axis
Hello Paul,
You can set the axis to show the complete datetime (dd/mm/yyy hh:mm) and then reformat the LabelText in the OnGetLabel event according to your needs.
Ie:
You can set the axis to show the complete datetime (dd/mm/yyy hh:mm) and then reformat the LabelText in the OnGetLabel event according to your needs.
Ie:
Code: Select all
uses DateUtils;
var tomorrow: TDateTime;
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
var date: TDateTime;
begin
Chart1.View3D:=False;
Chart1.Legend.Hide;
date:=Now;
tomorrow:=IncDay(date);
tomorrow:=EncodeDate(YearOf(tomorrow),MonthOf(tomorrow),DayOf(tomorrow));
with Chart1.AddSeries(TPointSeries) do
begin
XValues.DateTime:=True;
AddXY(date, 50+random*50);
for i:=1 to 48 do
begin
date:=IncHour(date);
AddXY(date, YValues[Count-1]+random*10-5);
end;
end;
Chart1.Axes.Bottom.DateTimeFormat:='dd/mm/yyyy hh:mm';
end;
procedure TForm1.Chart1GetAxisLabel(Sender: TChartAxis; Series: TChartSeries;
ValueIndex: Integer; var LabelText: string);
var date: TDateTime;
hour, min, tmp: Integer;
hourStr, minStr: string;
begin
if (Sender=Chart1.Axes.Bottom) and (Sender.IsDateTime) then
begin
date:=StrToDateTime(LabelText);
if (date>=tomorrow) then
begin
tmp:=DayOf(date-tomorrow)-DayOf(0)+1;
hour:=HourOf(date)+tmp*24;
min:=MinuteOf(date);
hourStr:=IntToStr(hour);
minStr:=IntToStr(min);
if Length(hourStr)=1 then
hourStr:='0'+hourStr;
if Length(minStr)=1 then
minStr:='0'+minStr;
LabelText:=hourStr+':'+minStr;
end
else
LabelText:=FormatDateTime('hh:mm', date);
end;
end;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |