How to simulate a zoom from the code ?

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Verane
Newbie
Newbie
Posts: 23
Joined: Thu Jan 09, 2003 5:00 am

How to simulate a zoom from the code ?

Post by Verane » Thu Jun 02, 2005 9:48 am

Hi,

I want to simulate that a user has made a zoom in a chart from the code.
For example, the Y scale goes from 0 to 1000, and when clicking on a button, I want it to go from 0 to 500, as if the user had made a zoom with the mouse.

I managed to do this by writing this piece of code in the event handler of my button:
private void button3_Click(object sender, System.EventArgs e)
{
mChart.Axes.Left.SetMinMax(0,500);
}


But the problem is that after doing that, it is impossible to unzoom again to 0-1000 y scale using the mouse (although you can do that if the zoom has been made by the mouse and not by the code).

Do I use the wrong function to simulate my zoom ?

Thanks for any help,

Verane.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Jun 02, 2005 10:16 am

Hi Verane,

Doing what you report then you can restore previous axes settings doing something like:

Code: Select all

		private void tChart1_Click(object sender, System.EventArgs e)
		{
			tChart1.Axes.Left.Automatic = !tChart1.Axes.Left.Automatic;
			tChart1.Axes.Bottom.Automatic = !tChart1.Axes.Bottom.Automatic;
		}
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Verane
Newbie
Newbie
Posts: 23
Joined: Thu Jan 09, 2003 5:00 am

Post by Verane » Thu Jun 02, 2005 11:41 am

Hi Narcis,
Thanks for your answer. But I don't think this could really work in my case. I want that the chart behaves exactly the same way as if I had done the zoom with the mouse.
With your suggestion, the problem is that the chart set back to the absolute scale (0-1000) as soon as I click on the chart.
What I would like to do is setting a particular zoom level to the chart, but without changing its absolute scale.
I was thinking that this was the role of the 'setMinMax' function (and I am not sure, but I think this was the case in the VCL version of the TeeChart) but apparently this function changes the absolute scale of the chart and not only the zoom level.
Do you see what I want to do exactly or maybe I am not clear ?
Thanks by advance,
Verane.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Jun 02, 2005 1:28 pm

Hi Verane,

Then you could use something like:

Code: Select all

		private void button1_Click(object sender, System.EventArgs e)
		{
			//tChart1.Zoom.ZoomPercent(149);						
			Rectangle r= Rectangle.FromLTRB(tChart1.Axes.Left.Position,
				tChart1.Axes.Left.IEndPos-(tChart1.Axes.Left.IAxisSize/2),
				tChart1.Axes.Bottom.IEndPos-(tChart1.Axes.Bottom.IAxisSize/2),
				tChart1.Axes.Bottom.Position);

			tChart1.Zoom.ZoomRect(r);
		}		  	

		private int X,Y;

		private void tChart1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			X=e.X;
			Y=e.Y;
		}

		private void tChart1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if ((X-e.X >=10) && (Y-e.Y >=10))  tChart1.Zoom.Undo();
		}
Using ZoomPercent up to 149 works fine but with values of 150 and above has a weird behaviour so you could use ZoomRect which would be as drawing the zoom rectangle with your mouse. To have the same undo zoom behaviour as with the mouse you can use tha code as done in MouseDown and MouseUp events.

Regarding SetMinMax, I don't understand exactly what you mean with:
With your suggestion, the problem is that the chart set back to the absolute scale (0-1000) as soon as I click on the chart.
What I would like to do is setting a particular zoom level to the chart, but without changing its absolute scale.
According to help files, for both .NET and VCL versions, SetMinMax definition is:

The SetMinMax method changes the current Axis Minimum and Maximum scales. The Axis.Automatic property is set to false.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Verane
Newbie
Newbie
Posts: 23
Joined: Thu Jan 09, 2003 5:00 am

Post by Verane » Mon Jun 06, 2005 7:51 am

Hi Narcis,
Thanks again for your reply.
About the meaning of 'setMinMax' in VCL, you were right, it is the same behaviour as in .NET.
I believed it was different, but I discover that in VCL we were obliged to derived the TeeChart to implement the functionnality that we want.
Before doing that again for .NET (which has a cost in time), I would like to be sure that no solution exists in the TeeChart (I would be very surprised if there is not). So I will try to explain you better my needs:

I can have several files opened in a browser. Clicking on any of this file in the browser shows a TeeChart containing a graph corresponding to the selected file. Each of those files can have different scales in X and in Y.
If I click on "file 1" for example in my browser (which has a proper scale that we will name SCALE1) and then make a zoom (then the scale is SCALE2 which is more accurate than SCALE1), I want that when clicking on file 2 (which has a proper scale that we will name SCALE3) the scale that is displayed is SCALE2 (which we suppose is more accurate than SCALE3, else it will be SCALE3 that is applied but it is not the point here).
Then when "file 2" is selected and displayed in the TeeChart with the SCALE2 scale, the user must be able to undo zoom until he gets back to the scale SCALE3.

So what I need, when the user clicks on "file 2" is to apply a different scale than its proper scale, but to be able to get back to the proper scale when doing undo zoom.
SetMinMax does not permit that. Once I have called this function, I can not get back to the original scale. I would like a function that changes just the zoom level, not the original scale.
And what I know about the scale I want to apply are the extrem values in X and in Y, but nothing in pixels.

Hope this is clearer.
Thanks for your help,
Verane.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Mon Jun 06, 2005 1:53 pm

Hi Verane,

I understand what you request but to help you with this, could you please send us a simple project, of what are you tyring to do, we can run "as-is"? You can post your examples at [url]news://www.steema.net/steema.public.attachments[/url] newsgroup.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply