Page 1 of 1

is shifting a series with the mouse possible?

Posted: Mon Sep 25, 2006 10:26 pm
by 9637279
Hi,

is there a way to select a series with a mouse and then
drag around? Motivation would be: you have a few
series plotted and you want to see how well a particular series
aligns with another one.
Made up example: Imagine you have two sinus like curves
that were recorded sequentially (i.e. x-axis not the same, y may
be different too). You want to pick with the mouse one of the
curves and drag is close to the other to see how well they match in
shape.

Thanks,
Norman

Posted: Fri Sep 29, 2006 2:50 pm
by narcis
Hi Norman,

Yes you can achieve doing something like this:

Code: Select all

      private bool clicked;
      private int origX, origY, X, Y, Index;

      private void Form1_Load(object sender, EventArgs e)
      {
          tChart1.Aspect.View3D = false;
          tChart1.Zoom.Allow = false;

          line1.FillSampleValues();
          line2.FillSampleValues();

          for (int i = 0; i < tChart1.Series.Count; i++)
          {
              tChart1[i].Click += new MouseEventHandler(Series_Click);
          }
      }

      void Series_Click(object sender, MouseEventArgs e)
      {
          SetClicked(e.X, e.Y, tChart1.Series.IndexOf(sender as Steema.TeeChart.Styles.Series));
      }      

      private void SetClicked(int X, int Y, int i)
      {
          clicked = true;
          Index = i;
          origX = X;
          origY = Y;
      }

      private void tChart1_MouseMove(object sender, MouseEventArgs e)
      {
          if (clicked)
          {
              X = e.X;
              Y = e.Y;

              tChart1.Refresh();
          }
      }

      private void tChart1_MouseUp(object sender, MouseEventArgs e)
      {
          clicked = false;
          tChart1.Refresh();
      }

      private void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
      {          
          if (clicked)
          {
              int diffX = X - origX;
              int diffY = Y - origY;
              Steema.TeeChart.Styles.Series s = tChart1[Index];

              for (int i = 0; i < s.Count-1; i++)
              {
                  Point p0 = new Point(s.CalcXPos(i) + diffX, s.CalcYPos(i) + diffY);
                  Point p1 = new Point(s.CalcXPos(i+1) + diffX, s.CalcYPos(i+1) + diffY);
                  g.Pen.Color = s.Color;
                  g.Line(p0, p1);
              }
          }
      }

Great!

Posted: Mon Oct 02, 2006 8:43 pm
by 9637279
This works great!
Thanks for this neat feature!