TpolarSeries and fillzone

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Calou
Advanced
Posts: 104
Joined: Wed Nov 19, 2008 12:00 am

TpolarSeries and fillzone

Post by Calou » Wed Jun 03, 2009 8:55 am

Hello,

I have a TpolarSeries and i am looking a way to fill each zone with a different color like the picture below

Image

Is it possible?

Thanks for help

@Yeray: I've edited you post to make the picture visible

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

Post by Yeray » Wed Jun 03, 2009 11:33 am

Hi Calou,

Here is an example:

Code: Select all

uses TeCanvas, Math;

var Colors: array of TColor;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  for i:=0 to 8 do
  begin
    if i > 0 then Series1.AddPolar(i*30, Series1.YValue[Series1.Count-1]);
    Series1.AddPolar(i*30, 0);
    if i < 8 then Series1.AddPolar(i*30, random*30);
  end;

  Series1.Pointer.Visible := false;

  SetLength(Colors,Series1.Count div 3);
  for i:=0 to length(Colors) do
  begin
    Colors[i] := RGB(Random(255), Random(255), Random(255));
  end;
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
var i: Integer;
    tmpPoints: TPointArray;
begin
  SetLength(tmpPoints,3);

  for i:=0 to Series1.Count-1 div 3 do
  begin
     tmpPoints[0].X := Series1.CalcXPos(i*3);
     tmpPoints[0].Y := Series1.CalcYPos(i*3);
     tmpPoints[1].X := Series1.CalcXPos(i*3+1);
     tmpPoints[1].Y := Series1.CalcYPos(i*3+1);
     tmpPoints[2].X := Series1.CalcXPos(i*3+2);
     tmpPoints[2].Y := Series1.CalcYPos(i*3+2);
     Chart1.Canvas.Brush.Color := Colors[i];
     Chart1.Canvas.Polygon(tmpPoints);
  end;
end;
PS: This may help when we'll implement the rose series (TV52013339)
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

Calou
Advanced
Posts: 104
Joined: Wed Nov 19, 2008 12:00 am

Post by Calou » Wed Jun 03, 2009 1:06 pm

Exactly what i wanted to do

Thank you very much

Calou
Advanced
Posts: 104
Joined: Wed Nov 19, 2008 12:00 am

Post by Calou » Thu Jun 04, 2009 1:08 pm

Hello,

Could it be possible to have in the legend the signification of the color

For example a green square and text for signification, a red square and an other text...
In my case i want legend for the color not for series values

Thanks

Regards

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

Post by Yeray » Thu Jun 04, 2009 2:34 pm

Hi Calou,

The possibility to have a fully customizable legend is already in the wish list (TV52010510). So I'm afraid that in the meanwhile the only solution you have is custom drawing to the canvas.
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

Calou
Advanced
Posts: 104
Joined: Wed Nov 19, 2008 12:00 am

Post by Calou » Fri Jun 05, 2009 9:13 am

Hello,
Ok for the legend

I have this code and i am surprised because the zone are not colored

Code: Select all

procedure TfrmRoseVent.DrawAllPetales(num_chart:integer;prjt:string);
var
  prctg_max,prctg,ind: Integer;
begin
...
  //parcours des enregs
  while not frmMain.IbcQryRd.Eof do
  begin
    //dessine le contour d'une pétale
    DrawPetale(num_chart,frmMain.IbcQryRd.FieldByName('ANGLE').AsInteger,frmMain.SpnEdtAngle.Value,prctg);
    ColorPetale(num_chart,ind,frmMain.IbcQryRd.FieldByName('VIT_MOY').AsFloat);
    frmMain.IbcQryRd.Next;
    Inc(ind,3);
  end;//fin du while parcours des enregs
end;

//dessine une petale de la rose
procedure TfrmRoseVent.DrawPetale(num_chart,angle_deb, pas_angle: integer; prctg: double);
begin
  //Déssine le contour
  TabSeriesRoseVent[num_chart].AddPolar(angle_deb,prctg);
  TabSeriesRoseVent[num_chart].AddPolar(angle_deb+pas_angle,prctg);
  TabSeriesRoseVent[num_chart].AddPolar(angle_deb+pas_angle,0);
end;

//colorie toutes les pétales
procedure TfrmRoseVent.ColorPetale(num_chart,ind_serie:integer ;vit_moy:double);
var
  tmp_pts: TPointArray;
begin
  SetLength(tmp_pts,3);
  //colorie
  tmp_pts[0].X:=TabSeriesRoseVent[num_chart].CalcXPos(ind_serie);
  tmp_pts[0].Y:=TabSeriesRoseVent[num_chart].CalcYPos(ind_serie);
  tmp_pts[1].X:=TabSeriesRoseVent[num_chart].CalcXPos(ind_serie+1);
  tmp_pts[1].Y:=TabSeriesRoseVent[num_chart].CalcYPos(ind_serie+1);
  tmp_pts[2].X:=TabSeriesRoseVent[num_chart].CalcXPos(ind_serie+2);
  tmp_pts[2].Y:=TabSeriesRoseVent[num_chart].CalcYPos(ind_serie+2);
  TabChrtRoseVent[num_chart].Canvas.Brush.Color := clYellow;
  TabChrtRoseVent[num_chart].Canvas.Polygon(tmp_pts);
end;
What could be wrong?

Thanks for help

Regards

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

Post by Yeray » Fri Jun 05, 2009 9:41 am

Hi Calou,

Yes, the problem is that drawing directly to the canvas needs to be done into an event that is called every time the chart is painted. For example at OnAfterDraw event.
So, you should call your ColorPetale method at OnAfterDraw for example.
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