Polygon to select data points?

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Juha
Newbie
Newbie
Posts: 6
Joined: Mon Jan 12, 2009 12:00 am
Location: Finland

Polygon to select data points?

Post by Juha » Tue Mar 03, 2009 12:01 pm

Hi

I have D7 and TeeChartPro 8.04. I'm quite new to this TeeChart so I'm making stupid questions:)

I can easily publish X/Y datapoints to chart but can I somehow draw polygon area a top of some points and say : "select/categorisate these points and paint area with x color"?
I need to make many categorisation for data points..

Thanks

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

Post by Yeray » Tue Mar 03, 2009 3:50 pm

Hi Juha,

There is not a series method to do this but here there is a proposition of how you could do it. It consists on creating a map series that will be the selector polygon. You create your polygon as a map series shape and then you'll be able to use its clicked method to see what points of your points series are in the area:

Code: Select all

uses series, TeeMapSeries;

procedure TForm1.FormCreate(Sender: TObject);
var
  ASerie: TMapSeries;
  APol: TTeePolygon;
  i: integer;
  PSerie: TPointSeries;
begin
  ASerie:=TMapSeries.Create(Chart1);
  ASerie.ParentChart:=Chart1;
  APol:=ASerie.Shapes.Add;

  with APol.Points do
  begin
    AddXY(1,1);
    AddXY(2,4);
    AddXY(0,7);
    AddXY(4,10);
    AddXY(5,8);
    AddXY(3,4);
    AddXY(5,2);
  end;

  PSerie:=TPointSeries.Create(Chart1);
  PSerie.ParentChart:=Chart1;
  PSerie.FillSampleValues(25);

  Chart1.Draw;
  Chart1.Title.Clear;
  for i:=0 to PSerie.Count-1 do
  begin
    if (ASerie.Clicked(PSerie.CalcXPos(i), PSerie.CalcYPos(i)) = 0) then
      Chart1.Title.Text.Add('Point ' + inttostr(i) + ' in the polygon');
  end;
end;
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

Juha
Newbie
Newbie
Posts: 6
Joined: Mon Jan 12, 2009 12:00 am
Location: Finland

Post by Juha » Thu Mar 05, 2009 2:19 pm

Thanks Yeray,
This example helped a lot!
But now I still have some problem because this "selector polygon" comes from external datapoints file.
So points are not in proper order to create nice polygon and polygon shape will be a mesh.
What is the best way to sort polygon datapoints that they will create a solid area/polygon - not crossing from arbitrary between points?
They would have to go around to center virtual point.
Any algorithm idea?
Thanks!
-juha

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

Post by Yeray » Thu Mar 05, 2009 4:24 pm

Hi Juha,

I think that determine a polygon having a random list of values could be a really complex study. But casually there is a chart tool that may help you very much in this work. Please, take a look at the demo at All features/Functions/Extended/Perimeter Function.

The combination of perimeter function and the map series could be your answer. I hope it will be.
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

Juha
Newbie
Newbie
Posts: 6
Joined: Mon Jan 12, 2009 12:00 am
Location: Finland

Post by Juha » Fri Mar 06, 2009 1:52 pm

Thanks a lot Yeray !
I solved my "polygon mesh" problem with this Perimeter function.
Just first reading XY points, then searching perimeters for them and finally giving these Perimeter points to MAP polygons - works !

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

Post by Yeray » Fri Mar 06, 2009 2:27 pm

Hi Juha,

I'm happy to see that you found a satisfactory solution. :D
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

Juha
Newbie
Newbie
Posts: 6
Joined: Mon Jan 12, 2009 12:00 am
Location: Finland

Post by Juha » Tue Mar 10, 2009 6:44 am

Back again :)
Everything works but how can I compare a given MapSeries array instead of this ASerie map?

I mean this:

1) this is working
if (ASerie.Clicked(PSerie.CalcXPos(i), PSerie.CalcYPos(i)) = 0) then

2) this is not working
if (Series1[5].Clicked(PSerie.CalcXPos(i), PSerie.CalcYPos(i)) = 0) then

So how can I use arrays maps to select these points?

Now I have done that like this way :
with APol.Points do begin
for i:=0 to series1[5].Points.count-1 do begin
AddXY(Series1[5].Points.XValue,Series1[5].Points.YValue);
end;
end;
But this is not sophisticated way because I have already "selection array" created..

Thanks
-Juha

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

Post by Yeray » Tue Mar 10, 2009 3:09 pm

Hi Juha,

We aren't sure to understand what are you exactly trying to achieve. Could you please try to explain more accurately or could you please send us a simple example project we can run "as-is" to reproduce the problem here?
You can either post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.
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

Post Reply