Page 1 of 1

Selection of series' points

Posted: Tue Jun 09, 2009 9:11 am
by 14048132
Greetings,

I want to select certain points of a sereis by draging a rectangle region.

I tried MouseDown and MouseUp events but just got the x-coordinates and y-coordinates in pixels (not relative to the values of x-axis and y-axis).

Do you have any suggestion about my requirement?

Thanks in advance.

Posted: Tue Jun 09, 2009 10:52 am
by yeray
Hi Chris,

Here there is a topic where something similar was discussed.

Re: Selection of series' points

Posted: Wed Jun 24, 2009 2:36 am
by 14048132
Greetings,

I want to highlight selected points after selection.

The way coming to my mind is to new a series of the selected points.
Then I could set the pointer style, color... any way I want to present the highlight.

But it seems not a good solution. Do you have any suggestion?

Re: Selection of series' points

Posted: Thu Jun 25, 2009 1:25 pm
by yeray
Hi Chris,

Here you have an example using the same series, simply changing the color of the selected points:

Code: Select all

uses TeCanvas;

var Selected: array of bool;
    DrawRectangle: bool;
    StartX, StartY: Integer;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D := false;
  Chart1.AllowZoom := false;
  DrawRectangle := false;

  Chart1[0].FillSampleValues(25);

  SetLength(Selected, Chart1[0].Count);
end;

procedure TForm1.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  DrawRectangle := true;
  StartX := X;
  StartY := Y;
end;

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if DrawRectangle then
  begin
    Chart1.Repaint;
    Chart1.Canvas.Brush.Style := bsClear;
    Chart1.Canvas.Rectangle(StartX, StartY, X, Y);
  end;
end;

procedure TForm1.Chart1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var i: Integer;
begin
  for i:=0 to length(Selected)-1 do
  begin
    if PointInRect(Rect(StartX, StartY, X, Y), Chart1[0].CalcXPos(i), Chart1[0].CalcYPos(i)) then
      Selected[i] := true
    else
      Selected[i] := false;
  end;

  DrawRectangle := false;
  Chart1.Repaint;
end;

function TForm1.Series1GetPointerStyle(Sender: TChartSeries;
  ValueIndex: Integer): TSeriesPointerStyle;
begin
  Result := psRectangle;
  if Selected[ValueIndex] then
    Sender.ValueColor[ValueIndex] := clRed
  else
    Sender.ValueColor[ValueIndex] := Sender.Color;
end;

Re: Selection of series' points

Posted: Fri Jun 26, 2009 2:12 am
by 14048132
Execuse me. Does this work in VB .NET version?

I try to implement it but encounter two problems:
1. The series.ValueColor[index] is a Read-Only property.
2. GetPointerStyle event is not found.

Re: Selection of series' points

Posted: Fri Jun 26, 2009 9:32 am
by 10050769
Hello Cris,
1. The series.ValueColor[index] is a Read-Only property.
You can do a similar code with next example, please check that this code works fine in your application:

Code: Select all

Private Sub p_GetPointerStyle(ByVal series As Steema.TeeChart.Styles.CustomPoint, ByVal e As Steema.TeeChart.Styles.GetPointerStyleEventArgs)
        series(e.ValueIndex).Color = Color.Orange
    End Sub
2. GetPointerStyle event is not found.
If you want to created even in VB you coud do so two ways:

First
: if you would to directly in run time(code), you needs to do next:

Code: Select all

AddHandler p.GetPointerStyle, AddressOf Me.p_GetPointerStyle
Second: if you would to design time, you have selected event

I hope will helps you,

Thanks,

Re: Selection of series' points

Posted: Mon Jun 29, 2009 2:20 am
by 14048132
[quote="Sandra"]Hello Cris,

You can do a similar code with next example, please check that this code works fine in your application:

Code: Select all

Private Sub p_GetPointerStyle(ByVal series As Steema.TeeChart.Styles.CustomPoint, ByVal e As Steema.TeeChart.Styles.GetPointerStyleEventArgs)
        series(e.ValueIndex).Color = Color.Orange
    End Sub

Greetings,

Thanks. It worked in my program. But my series is of the type Steema.TeeChart.Styles.Line.
This way would change not only the pointer's color but also the line associated with the pointer.
Is there any way to avoid this? I just want the pointer's style changed.

Thanks for you help.

Re: Selection of series' points

Posted: Mon Jun 29, 2009 8:10 am
by 10050769
Hello Cris,
Is there any way to avoid this? I just want the pointer's style changed.
Please check next code, that change only pointer's style, for example orange color.

Initialize: Add this two lines

Code: Select all

line.Pointer.Visible = true
AddHandler line.GetPointerStyle, AddressOf Me.line_GetPointerStyle
Line_GetPointerStyle Event:

Code: Select all

 Private Sub line_GetPointerStyle(ByVal series As Steema.TeeChart.Styles.CustomPoint, ByVal e As Steema.TeeChart.Styles.GetPointerStyleEventArgs)
        e.Color = Color.Orange
 End Sub
I hope that will helps

Thanks,

Re: Selection of series' points

Posted: Tue Jul 07, 2009 7:06 am
by 14048132
Greetings,

I enabled the zooming tool after highlighting but met some problems.
The line associated with the highlighted points would be drawed outside the chart region.

Before zooming:
3_.GIF
before zooming
3_.GIF (49.25 KiB) Viewed 19425 times
After zooming:
4_.GIF
after zooming
4_.GIF (13.75 KiB) Viewed 19424 times
Do you have any iedas about this?

Re: Selection of series' points

Posted: Tue Jul 07, 2009 10:17 am
by 10050769
Hello Cris,
Do you have any iedas about this?
I have commented two things:

First:
Is possible that you have property tChart1.Aspect.ClipPoint= false, change this for true. I check with last version and works fine.

Second: If previous not works, please you could say what is your actualy version of TeeChartFor .Net?

If your version isn't laster, please update the version and tester code.If the problem still appears you can send a simple example because we can reproduce here. Now,you can attach your projecte direcly in the forums post.

Thanks.

Re: Selection of series' points

Posted: Thu Jul 16, 2009 3:11 pm
by 14048132
Sandra wrote:Hello Cris,
Is there any way to avoid this? I just want the pointer's style changed.
Please check next code, that change only pointer's style, for example orange color.

Initialize: Add this two lines

Code: Select all

line.Pointer.Visible = true
AddHandler line.GetPointerStyle, AddressOf Me.line_GetPointerStyle
Line_GetPointerStyle Event:

Code: Select all

 Private Sub line_GetPointerStyle(ByVal series As Steema.TeeChart.Styles.CustomPoint, ByVal e As Steema.TeeChart.Styles.GetPointerStyleEventArgs)
        e.Color = Color.Orange
 End Sub
I hope that will helps

Thanks,
Hi,

Coule I draw a circle on the outside of the pointer?

Please see the below image.
33.GIF
33.GIF (23.7 KiB) Viewed 19337 times

Re: Selection of series' points

Posted: Fri Jul 17, 2009 12:56 pm
by 10050769
Hello Chris,

I find two solutions for draw a circle, in your selection. The first solution is more simple than the second, but both make a circle around the pointer.

Firts solution:
Using GetPointStyles

Code: Select all

bool[] Selected;
        Steema.TeeChart.Styles.Line line;
        bool drawrectangle;
        Rectangle rect;

        private void InitializeChart()
        {
            line = new Steema.TeeChart.Styles.Line (tChart1.Chart);
            line.FillSampleValues();
            line.Pointer.Visible = true;
            tChart1.Aspect.View3D = false;
            tChart1.Aspect.ClipPoints = true;
            drawrectangle = false;
            Selected = new bool[line.Count];
            tChart1.Panning.MouseButton = MouseButtons.Middle;
            tChart1.MouseMove += new MouseEventHandler(tChart1_MouseMove);
            tChart1.MouseUp += new MouseEventHandler(tChart1_MouseUp);
            tChart1.MouseDown += new MouseEventHandler(tChart1_MouseDown);
            tChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);
           line.GetPointerStyle += new Steema.TeeChart.Styles.CustomPoint.GetPointerStyleEventHandler(line_GetPointerStyle);
            tChart1.Draw();
            ResetCoords();
      
        }

        void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            if ((X0 != -1) && (Y0 != -1))
            {
                if (drawrectangle)
                {
                    g.Brush.Visible = false;
                    g.Pen.Color = Color.Black;
                    g.Rectangle(X0, Y0, X1, Y1);

                }
            }       
        }
 void tChart1_MouseDown(object sender, MouseEventArgs e)
        {
           
            if (e.Button == MouseButtons.Right)
            {
                drawrectangle = true;
                X0 = e.X;
                Y0 = e.Y;
            }
            
        }

        void tChart1_MouseUp(object sender, MouseEventArgs e)
        {
           if ((X0 != -1) && (Y0 != -1))
            {                
                rect = new Rectangle(X0, Y0, e.X -X0, e.Y-Y0);
                for (int i = 0; i < Selected.Length; i++)
                {
                    Point p = new Point(tChart1[0].CalcXPos(i), tChart1[0].CalcYPos(i));
                    if (rect.Contains(p))
                    {
                        Selected[i] = true;
                        
                    }
                    else
                    {
                        Selected[i] = false;
                    }
                  
                }

               ResetCoords();
            }
            drawrectangle = false;
            tChart1.Draw();

        }
        private int X0, Y0, X1, Y1;

        void tChart1_MouseMove(object sender, MouseEventArgs e)
        {

                    if (e.Button == MouseButtons.Right)
                    {
                        X1 = e.X;
                        Y1 = e.Y;
                    }
                tChart1.Invalidate();    

        }

        void line_GetPointerStyle(Steema.TeeChart.Styles.CustomPoint series, Steema.TeeChart.Styles.GetPointerStyleEventArgs e)
        {
            e.Style = Steema.TeeChart.Styles.PointerStyles.Circle;
            
            if (Selected[e.ValueIndex])
            {
                series.Pointer.Pen.Color = Color.Red;
                series.Pointer.Pen.Width = 2;
            }
            else
            {
                series.Pointer.Pen.Color = series.Color;
                series.Pointer.Pen.Width = 1;
            }
        }
        private void ResetCoords()
        {
            X0= -1;
            Y0= -1;
        }

Second solution: Using AfterDraw and drawing directly in canvas.

Code: Select all

    bool[] Selected;
        Steema.TeeChart.Styles.Line line;
        bool drawrectangle;
        Rectangle rect;

        private void InitializeChart()
        {
            line = new Steema.TeeChart.Styles.Line(tChart1.Chart);
            line.FillSampleValues();
            line.Pointer.Visible = true;
            tChart1.Aspect.View3D = false;
            tChart1.Aspect.ClipPoints = true;
            drawrectangle = false;
            Selected = new bool[line.Count];
            tChart1.Panning.MouseButton = MouseButtons.Middle;
            tChart1.MouseMove += new MouseEventHandler(tChart1_MouseMove);
            tChart1.MouseUp += new MouseEventHandler(tChart1_MouseUp);
            tChart1.MouseDown += new MouseEventHandler(tChart1_MouseDown);
            tChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);
           line.GetPointerStyle += new Steema.TeeChart.Styles.CustomPoint.GetPointerStyleEventHandler(line_GetPointerStyle);
            tChart1.Draw();
            ResetCoords();
      
        }

        void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            if ((X0 != -1) && (Y0 != -1))
            {
                if (drawrectangle)
                {
                    g.Brush.Visible = false;
                    g.Pen.Color = Color.Black;
                    g.Rectangle(X0, Y0, X1, Y1);

                }
            }
            for (int i = 0; i < Selected.Length; i++)
            {
                Point p = new Point(tChart1[0].CalcXPos(i), tChart1[0].CalcYPos(i));
                Rectangle rect1 = new Rectangle(p.X - line.Pointer.HorizSize - 5, p.Y - line.Pointer.VertSize - 5, (line.Pointer.HorizSize + 5) * 2, (line.Pointer.VertSize + 5) * 2);


                if (Selected[i])
                {
                    g.Brush.Visible = false;
                    g.Pen.Color = Color.Blue;
                    g.Ellipse(rect1);
                }

            }

        }
   void tChart1_MouseDown(object sender, MouseEventArgs e)
        {
           
            if (e.Button == MouseButtons.Right)
            {
                drawrectangle = true;
                X0 = e.X;
                Y0 = e.Y;
            }
            
        }

        void tChart1_MouseUp(object sender, MouseEventArgs e)
        {
           if ((X0 != -1) && (Y0 != -1))
            {                
                rect = new Rectangle(X0, Y0, e.X -X0, e.Y-Y0);
                for (int i = 0; i < Selected.Length; i++)
                {
                    Point p = new Point(tChart1[0].CalcXPos(i), tChart1[0].CalcYPos(i));
                    if (rect.Contains(p))
                    {
                        Selected[i] = true;
                        
                    }
                    else
                    {
                        Selected[i] = false;
                    }
                  
                }

               ResetCoords();
            }
            drawrectangle = false;
            tChart1.Draw();

        }
        private int X0, Y0, X1, Y1;

        void tChart1_MouseMove(object sender, MouseEventArgs e)
        {

                    if (e.Button == MouseButtons.Right)
                    {
                        X1 = e.X;
                        Y1 = e.Y;
                    }
                tChart1.Invalidate();    

        }

        void line_GetPointerStyle(Steema.TeeChart.Styles.CustomPoint series, Steema.TeeChart.Styles.GetPointerStyleEventArgs e)
        {
            e.Style = Steema.TeeChart.Styles.PointerStyles.Circle;
            
            if (Selected[e.ValueIndex])
            {
                e.Color = Color.Red;

            }     
        }
        private void ResetCoords()
        {
            X0= -1;
            Y0= -1;
        }
Please, check that previous codes works correctly in your application.

I hope will helps.

Thanks,

Re: Selection of series' points

Posted: Wed Mar 17, 2010 8:53 am
by 8574101
Thanks!