Page 1 of 1

TChart Allow zoom

Posted: Mon Jan 17, 2005 2:06 am
by 9235196
I write the save and load chart by myself. Because there is many more things to be saved in my application.
What property can be affected by allow zoom?
I want to save the things after user doing zooming in a chart.
But I don't know what property to be saved.

Thank you

Herman

Posted: Mon Jan 17, 2005 7:31 am
by Pep
Hi Herman,

it's saved in the Allow property, i.e :
Chart1.Zoom.Allow := true;

Posted: Mon Jan 17, 2005 9:38 am
by 9235196
AllowZoom is just a boolean isn't?
then how to know, the position that user have click on a chart for zooming

Posted: Mon Jan 17, 2005 11:33 am
by Marjan
Hi.

You can use the chart OnZoom event to retrieve zoom rectangle start and end position:

Code: Select all

procedure TForm1.Chart1Zoom(Sender: TObject);
var startpoint, endpoint: TPoint;
begin
  startpoint.X := Chart1.Zoom.X0;
  startpoint.Y := Chart1.Zoom.Y0;
  endpoint.X := Chart1.Zoom.X1;
  endpoint.Y := Chart1.Zoom.Y1;
end;
Please note that startpoint and endpoint denote the zooming rectangle start and end point, expressed in screen pixels. If you want real axis values, use chart axis CalcPosPoint method for transformation.

Posted: Tue Jan 18, 2005 5:41 am
by 9235196
It still not working. I test like this.
Add samething to chart1 and chart2.
Chart1's allowzoom is set to true.
Then i zoom some part of chart1. Then click apply changes to chart2.
I want it to display the same thing.
Instead of using chart2->Assign(chart1).
I want to know exactly what property effected by allowzoom.

void __fastcall TForm1::Add(Tobject *Sender)
{
int i;

for(i = 0; i < 501; i++)
{
Chart1->Series[0]->AddY(i*10);
Chart2->Series[0]->AddY(i*10);
}
}

void __fastcall TForm1::Apply(TObject *Sender)
{
Chart2->Zoom->X0 = Chart1->Zoom->X0;
Chart2->Zoom->X1 = Chart1->Zoom->X1;
Chart2->Zoom->Y0 = Chart1->Zoom->Y0;
Chart2->Zoom->Y1 = Chart1->Zoom->Y1;

}

Posted: Tue Jan 18, 2005 10:17 am
by 9235196
I have found the property that could possibly affect by allowzoom.
Not so sure...but it does show the things i want.
My sample code is like this:

Chart2->LeftAxis->Automatic = false;
Chart2->LeftAxis->AutomaticMinimum = false;
Chart2->LeftAxis->AutomaticMaximum = false;

Chart2->LeftAxis->Minimum = Chart1->LeftAxis->Minimum;
Chart2->LeftAxis->MinimumOffset = Chart1->LeftAxis->MinimumOffset;
Chart2->LeftAxis->Maximum = Chart1->LeftAxis->Maximum;
Chart2->LeftAxis->MaximumOffset = Chart1->LeftAxis->MaximumOffset;

Chart2->BottomAxis->Automatic = false;
Chart2->BottomAxis->AutomaticMinimum = false;
Chart2->BottomAxis->AutomaticMaximum = false;

Chart2->BottomAxis->Minimum = Chart1->BottomAxis->Minimum;
Chart2->BottomAxis->MinimumOffset = Chart1->BottomAxis->MinimumOffset;
Chart2->BottomAxis->Maximum = Chart1->BottomAxis->Maximum;
Chart2->BottomAxis->MaximumOffset = Chart1->BottomAxis->MaximumOffset;

Posted: Tue Jan 18, 2005 1:59 pm
by Marjan
Hi, Herman.

Yes. Zooming and scrolling ulitmately only changes axis scales (explained in TeeChart VCL FAQ, see this link).
When you're zooming or scrolling chart the end result is chart axis minimum and maximum values will change. So, if you know axis ranges (minimum and maximum values), you can copy these properties to second chart and you'll get a synchronized zoom.