Page 1 of 1

Centre chart at Tlineseries X and Y

Posted: Wed Jul 20, 2005 8:09 pm
by 9231397
Chart with lineseries, <1000 x and y values forming a curve. I would like to zoom right into the data so only about 30 points are displayed on chart. Would then like to have the chart cycle through the data one point at a time, ie. scrolling along the curve, always showing 30 points. One way to do this would be to centre the chart on [x1,y1], then [x2,y2], then [x3,y3] etc. Is there a way to centre a chart on any [x,y] pair?

thanks
Sean

Posted: Thu Jul 21, 2005 7:52 am
by narcis
Hi Sean,

Yes, this can be done getting [X,Y] pair values and setting left and bottom axes accordingly as shown in the code below. In this example two options are shown:

1) The Button1Click code centers the chart to the center value of the series.

2) The Timer1Timer code authomatically scrolls series starting at its center and looping through series points.

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  for i:=0 to 100 do Series1.AddXY(i,i*i);
  CenterIndex:=Series1.Count div 2;

  Timer1.Enabled:=false;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  With Chart1.Axes do
  begin
    Left.SetMinMax(Series1.YValue[CenterIndex]-Series1.YValue[CenterIndex-10],
                    Series1.YValue[CenterIndex]+Series1.YValue[CenterIndex+10]);
    Bottom.SetMinMax(Series1.XValue[CenterIndex]-Series1.XValue[CenterIndex-10],
                    Series1.XValue[CenterIndex]+Series1.XValue[CenterIndex+10]);
  end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  With Chart1.Axes do
  begin
    Left.SetMinMax(Series1.YValue[CenterIndex]-Series1.YValue[CenterIndex-10],
                    Series1.YValue[CenterIndex]+Series1.YValue[CenterIndex+10]);
    Bottom.SetMinMax(Series1.XValue[CenterIndex]-Series1.XValue[CenterIndex-10],
                    Series1.XValue[CenterIndex]+Series1.XValue[CenterIndex+10]);
  end;

  if CenterIndex=100 then CenterIndex:=0
  else inc(CenterIndex);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Timer1.Enabled:=true;
end;