Page 1 of 1

Problem with zooming in two tee chart

Posted: Thu Oct 01, 2009 11:55 am
by 9641422
Hi,
While we use two tee charts having same width and height and allow zooming in both tee charts.
Our requirement is whenever we perform zooming in first tee chart then second tee chart should also zoomed automatically with the same ratio as per first tee chart.
Please let us know how can it be possible?

Gautam

Re: Problem with zooming in two tee chart

Posted: Thu Oct 01, 2009 1:48 pm
by yeray
Hi Gautam,

Here is an example of how you could do it. You should do the zooms manually because otherwise, calling the Chart2.Zoom.ZoomRect at Chart1's Zoomed event and the same at reverse, it will result in a infinite loop when you'll zoom.

Code: Select all

        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            tChart2.Aspect.View3D = false;

            Steema.TeeChart.Styles.Points points1 = new Steema.TeeChart.Styles.Points();

            points1.FillSampleValues(25);
            Steema.TeeChart.Styles.Points points2 = (Steema.TeeChart.Styles.Points)points1.Clone();
            tChart1.Series.Add(points1);
            tChart2.Series.Add(points2);
            points1.Color = Color.CadetBlue;
            points2.Color = Color.BlueViolet;

            tChart1.Zoom.Allow = false;
            tChart1.Panning.Allow = Steema.TeeChart.ScrollModes.None;
            tChart2.Zoom.Allow = false;
            tChart2.Panning.Allow = Steema.TeeChart.ScrollModes.None;

            tChart1.MouseDown += new MouseEventHandler(tChart1_MouseDown);
            tChart1.MouseUp += new MouseEventHandler(tChart1_MouseUp);
            tChart1.MouseMove += new MouseEventHandler(tChart1_MouseMove);
            tChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);

            tChart2.MouseDown += new MouseEventHandler(tChart1_MouseDown);
            tChart2.MouseUp += new MouseEventHandler(tChart1_MouseUp);
            tChart2.MouseMove += new MouseEventHandler(tChart2_MouseMove);
            tChart2.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart2_AfterDraw);
        }

        private int MouseDownX, MouseDownY, MouseActX, MouseActY;
        private bool Zooming;

        void tChart1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                MouseDownX = e.X;
                MouseDownY = e.Y;
                Zooming = true;                
            }
        }

        void tChart1_MouseUp(object sender, MouseEventArgs e)
        {
            if (Zooming)
            {
                if ((e.X < MouseDownX) && (e.Y < MouseDownY))
                {
                    tChart1.Axes.Left.Automatic = true;
                    tChart1.Axes.Bottom.Automatic = true;
                    tChart1.Invalidate();
                    tChart2.Axes.Left.Automatic = true;
                    tChart2.Axes.Bottom.Automatic = true;
                    tChart2.Invalidate();
                }
                else
                {
                    tChart1.Axes.Left.SetMinMax(tChart1.Axes.Left.CalcPosPoint(e.Y), tChart1.Axes.Left.CalcPosPoint(MouseDownY));
                    tChart1.Axes.Bottom.SetMinMax(tChart1.Axes.Bottom.CalcPosPoint(MouseDownX), tChart1.Axes.Bottom.CalcPosPoint(e.X));
                    tChart2.Axes.Left.SetMinMax(tChart2.Axes.Left.CalcPosPoint(e.Y), tChart2.Axes.Left.CalcPosPoint(MouseDownY));
                    tChart2.Axes.Bottom.SetMinMax(tChart2.Axes.Bottom.CalcPosPoint(MouseDownX), tChart2.Axes.Bottom.CalcPosPoint(e.X));
                }
            }
            Zooming = false;
        }

        void tChart1_MouseMove(object sender, MouseEventArgs e)
        {
            if (Zooming)
            {
                MouseActX = e.X;
                MouseActY = e.Y;
                tChart1.Invalidate();
            }
        }

        void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            if (Zooming)
            {
                tChart1.Graphics3D.Pen.Style = System.Drawing.Drawing2D.DashStyle.Dash;
                tChart1.Graphics3D.BackColor = Color.Empty;
                tChart1.Graphics3D.Rectangle(MouseDownX, MouseDownY, MouseActX, MouseActY);
            }
        } 

        void tChart2_MouseMove(object sender, MouseEventArgs e)
        {
            if (Zooming)
            {
                MouseActX = e.X;
                MouseActY = e.Y;
                tChart2.Invalidate();
            }
        }

        void tChart2_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            if (Zooming)
            {
                tChart2.Graphics3D.Pen.Style = System.Drawing.Drawing2D.DashStyle.Dash;
                tChart2.Graphics3D.BackColor = Color.Empty;
                tChart2.Graphics3D.Rectangle(MouseDownX, MouseDownY, MouseActX, MouseActY);
            }
        }

Re: Problem with zooming in two tee chart

Posted: Sat Oct 03, 2009 6:58 am
by 9641422
Hi Yeray ,

thanks for ur reply.
Now, my problem is solved.

Gautam