Page 1 of 1

Dates before 1900 are left out

Posted: Thu Jul 23, 2009 9:27 am
by 10553957
I have use for displaying dates before 1900. back to 1850 as a matter of fact. :shock:

For some reason, TChart omits dates before 1900, producing a rather strange result :? . Check the attachment.

Regards - Hans

Here's the patch:

Code: Select all

Function TChartAxis.LabelValue(Const Value:Double):String;
var tmp : String;
Begin
  if IAxisDateTime then
  begin
{$ifdef HH_PATCH_TC_DATETIME}
    if true then // I also want dates before 01-01-1900 !!!
{$else}
    if Value>=0 then
{$endif}
    Begin
      if FDateTimeFormat='' then tmp:=DateTimeDefaultFormat(IRange)
                            else tmp:=FDateTimeFormat;
      DateTimeToString(result,tmp,Value);
    end
    else result:='';
  end
  else result:=FormatFloat(FAxisValuesFormat,Value);

  if Assigned(ParentChart.FOnGetAxisLabel) then
     ParentChart.FOnGetAxisLabel(TChartAxis(Self),nil,-1,Result);

  if FLabelsMultiLine then
     result:=ReplaceChar(result,' ',TeeLineSeparator);
end;

Re: Dates before 1900 are left out

Posted: Thu Jul 23, 2009 12:52 pm
by yeray
Hi Hans,

The delphi's DateTimeToString function seems to manage correctly both positive and negative values, so I'm not sure on the reason of the "if Value>=0 then" condition (note that negative doubles represent dates before 30/12/1899).

So here is how is right now the function. You could modify your TeEngine.pas or wait until the next maintenance release.

Code: Select all

Function TChartAxis.LabelValue(Const Value:Double):String;
var tmp : String;
Begin
  if IAxisDateTime then
  begin
    if FDateTimeFormat='' then tmp:=DateTimeDefaultFormat(IRange)
                          else tmp:=FDateTimeFormat;
    DateTimeToString(result,tmp,Value);
  end
  else result:=FormatFloat(FAxisValuesFormat,Value);

  if Assigned(ParentChart.FOnGetAxisLabel) then
     ParentChart.FOnGetAxisLabel(TChartAxis(Self),nil,-1,Result);

  if FLabelsMultiLine then
     result:=ReplaceChar(result,' ',TeeLineSeparator);
end;