Page 1 of 1

Go to Date

Posted: Thu Mar 19, 2009 12:04 pm
by 10549967
I have a line graph with the x-axis as DateTime. I would like to be able to go to today's date in the graph when the window is first displayed. Is there an easy way to do this?

Thanks.

Posted: Fri Mar 20, 2009 8:56 am
by yeray
Hi alexiat,

Yes, you should set your bottom axis min and max manually. Here is a simple example:

Code: Select all

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

  Chart1.AddSeries(TLineSeries.Create(nil));

  Chart1[0].XValues.DateTime := true;
  (Chart1[0] as TLineSeries).Pointer.Visible := true;

  day := Today - 100;

  for i:=0 to 500 do
    Chart1[0].AddXY((day + i), i*i);

  Chart1.Axes.Bottom.SetMinMax(Today - 3, Today + 3);
end;

Posted: Fri Mar 20, 2009 4:08 pm
by 10549967
Thank you!