Page 1 of 1

Zoom/Unzoom using mouse button click

Posted: Thu Oct 22, 2009 12:01 am
by 15654246
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

Re: Zoom/Unzoom using mouse button click

Posted: Thu Oct 22, 2009 10:39 am
by 10050769
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,

Re: Zoom/Unzoom using mouse button click

Posted: Thu Oct 22, 2009 9:57 pm
by 15654246
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

Re: Zoom/Unzoom using mouse button click

Posted: Fri Oct 23, 2009 7:57 am
by 10050769
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,

Re: Zoom/Unzoom using mouse button click

Posted: Mon Nov 30, 2009 12:33 pm
by 15654246
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

Re: Zoom/Unzoom using mouse button click

Posted: Mon Nov 30, 2009 3:21 pm
by narcis
Hi Avijit,

Please see my reply about the same question.

Thanks in advance.

Re: Zoom/Unzoom using mouse button click

Posted: Mon Nov 30, 2009 3:50 pm
by narcis
Hi Avijit,

For completeness, for being able to unzoom step by step you need to have zoomed with History set to true.

Re: Zoom/Unzoom using mouse button click

Posted: Tue Dec 01, 2009 5:38 pm
by 15654246
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

Re: Zoom/Unzoom using mouse button click

Posted: Wed Dec 02, 2009 3:51 pm
by yeray
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.

Re: Zoom/Unzoom using mouse button click

Posted: Mon Dec 14, 2009 7:54 am
by 15654593
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

Re: Zoom/Unzoom using mouse button click

Posted: Mon Dec 14, 2009 8:09 am
by 15654246
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

Re: Zoom/Unzoom using mouse button click

Posted: Mon Dec 14, 2009 8:24 am
by 15654593
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

Re: Zoom/Unzoom using mouse button click

Posted: Mon Dec 14, 2009 8:41 am
by 15654246
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

Re: Zoom/Unzoom using mouse button click

Posted: Mon Dec 14, 2009 8:51 am
by 15654593
Hi Avijit,

Thanks alot. It's work. Thank you.

Regards,
Nicholas