Zoom/Unzoom using mouse button click

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Avijit
Newbie
Newbie
Posts: 72
Joined: Tue Sep 15, 2009 12:00 am

Zoom/Unzoom using mouse button click

Post by Avijit » Thu Oct 22, 2009 12:01 am

Hi,
I want to disable the zooming and unzooming using the dragging of mouse downwords and upwords. How can i do it?
Instead i want to add two buttons in my toolbar say Zoom button and Unzoom button.
Now when user clicked the Zoom button in the toolbar, the mouse cursor should get changed to a zoom cursor(some visual indication). After that if user drag the mouse in any direction in a perticular area of the chart control that area should get zoomed.
Similarly when user clicks the Unzoom button in the tool bar the mouse cursor should change to Unzoom cursor. After that, if user clicks the mouse button then the chart control should get unzoomed. May be by step by step unzoom or at a time unzoom.
How can i achive this using TeeChart control?
Thanks in advance for your help.

Regards,
Avijit

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Zoom/Unzoom using mouse button click

Post by Sandra » Thu Oct 22, 2009 10:39 am

Hello Avijit,

I could make a simple example that I think solve your problem. Please check that next example works as you want:

Code: Select all

  Steema.TeeChart.Styles.Line line1;
        bool zooming;
        private Rectangle rect;
        private void InitializeChart()
        {

            line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
            line1.FillSampleValues(20);
            tChart1.MouseDown += new MouseEventHandler(tChart1_MouseDown);
            tChart1.MouseUp += new MouseEventHandler(tChart1_MouseUp);
            tChart1.MouseMove += new MouseEventHandler(tChart1_MouseMove);
            zooming = false;
            tChart1.Zoom.Allow = false;
            tChart1.Zoom.History = checkBox1.Checked;    

        }

        void tChart1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (zooming && (rect.X != 0) && (rect.Y != 0))
                {
                    rect.Width = e.X - rect.Left;
                    rect.Height = e.Y - rect.Top;

                }
                Rectangle tmpRect = rect;

                if (tmpRect.Width < 0)
                {
                    tmpRect.X = rect.X - Math.Abs(rect.Width);
                    tmpRect.Width = x - tmpRect.X;
                }

                if (rect.Height < 0)
                {
                    tmpRect.Y = rect.Y - Math.Abs(rect.Height);
                    tmpRect.Height = y - tmpRect.Y;
                }

                tChart1.Graphics3D.Brush.Transparency = 100;
                tChart1.Graphics3D.Rectangle(tmpRect);
                
            }
            tChart1.Invalidate();
        }

        void tChart1_MouseUp(object sender, MouseEventArgs e)
        {
            rect.Width = e.X - rect.Left;
            rect.Height = e.Y - rect.Top;

            if (zooming)
            {    
                tChart1.Zoom.ZoomRect(rect);
                rect = new Rectangle(0, 0, 0, 0);
            }
        }

        private int x, y;

        void tChart1_MouseDown(object sender, MouseEventArgs e)
        {
    
            rect = new Rectangle(e.X, e.Y, 0, 0);
            x = e.X;
            y = e.Y;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            zooming = true;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            tChart1.Zoom.Undo();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            tChart1.Zoom.History = checkBox1.Checked;
        }
I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / 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

Avijit
Newbie
Newbie
Posts: 72
Joined: Tue Sep 15, 2009 12:00 am

Re: Zoom/Unzoom using mouse button click

Post by Avijit » Thu Oct 22, 2009 9:57 pm

Hi Sandra,
Thanks for your reply.

One very important thing that i should have mentioned in my previous post is - i cannot invalidate or refresh the TeeChart control during MouseMove event or any event that will occur very frequently. Because we are showing huge amount of data at a time and if we call Invalidate or refresh it will be a very big performance issue. So i did not yet tested your code in my application but it looks like it will work if we can just remove the invalidate call from the MoveMove event. May be i should use ReversibleRectangle?? Any suggetion?

Regards,
Avijit

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Zoom/Unzoom using mouse button click

Post by Sandra » Fri Oct 23, 2009 7:57 am

Hello Avijit,

I recomend two thinks:

First, you have an option of RebercibleRectangle. Other, you could not paint rectangle, you only have deleted all the code that you use for draw of rectangle(tmpRect).If you choose this option, performance are smaller and Zoom will continue doing.


I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / 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

Avijit
Newbie
Newbie
Posts: 72
Joined: Tue Sep 15, 2009 12:00 am

Re: Zoom/Unzoom using mouse button click

Post by Avijit » Mon Nov 30, 2009 12:33 pm

Hi Sandra,
I have one query -
The code you have written below - in the Unzoom part if i call Undo() function directly then the control is getting reset to its normal view at a time irrespective of the History zoom checkbox.
How to unzoom step by step?

Regards,
Avijit

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

Re: Zoom/Unzoom using mouse button click

Post by Narcís » Mon Nov 30, 2009 3:21 pm

Hi Avijit,

Please see my reply about the same question.

Thanks in advance.
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

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

Re: Zoom/Unzoom using mouse button click

Post by Narcís » Mon Nov 30, 2009 3:50 pm

Hi Avijit,

For completeness, for being able to unzoom step by step you need to have zoomed with History set to true.
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

Avijit
Newbie
Newbie
Posts: 72
Joined: Tue Sep 15, 2009 12:00 am

Re: Zoom/Unzoom using mouse button click

Post by Avijit » Tue Dec 01, 2009 5:38 pm

Hi Narcis,
Thanks for your reply.
After trying few things i have decided to not to use the normal zooming functionality that has been provided by TeeChart.
I have set -
TeeChart.Zoom.Allow = false;

Instead i am using the SetMinMax function of the Axis for zooming.
Now zooming is working as i expected.
But with these approach i am not able to get the advantage of History Unzooming.
I have 10 custom Y axis so that each data series can have its own place without overlaping with each other.
Please let me know how can i achieve the History zooming i that case.

Regards,
Avijit

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Zoom/Unzoom using mouse button click

Post by Yeray » Wed Dec 02, 2009 3:51 pm

Hi Avijit,

In that case you'll have to store you own history. You could have a two dimension array for each custom axis. When you zoom in, you add the min and max of each axis before zooming so you will be able to restore them in the zoom out procedure.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

nicholasamh
Newbie
Newbie
Posts: 8
Joined: Wed Nov 04, 2009 12:00 am

Re: Zoom/Unzoom using mouse button click

Post by nicholasamh » Mon Dec 14, 2009 7:54 am

Hi,
I am using the code you gave above but i am having a problem when i selected zoom in and i click on the chart. The chart will become blank and my line is missing. Only when i click on zoom out then i come back again. Please help me out with that by providing me the code. Thanks

Regards,
Nicholas

Avijit
Newbie
Newbie
Posts: 72
Joined: Tue Sep 15, 2009 12:00 am

Re: Zoom/Unzoom using mouse button click

Post by Avijit » Mon Dec 14, 2009 8:09 am

Hi,
I also got the same problem once.
I think you have to check the mouse down and mouse up value before even doing anything with zoom.
If these two values are same you need not go ahead and zoom. Just return from there.
hope this will solve the problem.

Regards,
Avijit

nicholasamh
Newbie
Newbie
Posts: 8
Joined: Wed Nov 04, 2009 12:00 am

Re: Zoom/Unzoom using mouse button click

Post by nicholasamh » Mon Dec 14, 2009 8:24 am

Hi Avijit,

I am new to using teechart. Is it checking the x and y value of MouseDown, and rect.Width and rect.Height of MouseUp? If u can, please give me a simple code. Sorry and thanks alot.

Regards,
Nicholas

Avijit
Newbie
Newbie
Posts: 72
Joined: Tue Sep 15, 2009 12:00 am

Re: Zoom/Unzoom using mouse button click

Post by Avijit » Mon Dec 14, 2009 8:41 am

Hi,
See below the sample code.

Code: Select all

     int ZoomX, ZoomY;
     private void tChart1_MouseDown(object sender, MouseEventArgs e)
      {
          if (tChart1.Series.Count <= 0) return;
          if (e.Button == MouseButtons.Left)
          {
            ZoomX = e.X;
            ZoomY = e.Y;
          }
      }
      private void tChart1_MouseUp(object sender, MouseEventArgs e)
      {
            if (e.X == ZoomX && e.Y == ZoomY) return;
      }
Hope this will help.

Regards,
Avijit

nicholasamh
Newbie
Newbie
Posts: 8
Joined: Wed Nov 04, 2009 12:00 am

Re: Zoom/Unzoom using mouse button click

Post by nicholasamh » Mon Dec 14, 2009 8:51 am

Hi Avijit,

Thanks alot. It's work. Thank you.

Regards,
Nicholas

Post Reply