Drawing Filled Polygons in RChart

Problem How can I draw filled polygons in RChart? I need to draw polygons in the coordinate system of the chart which can be zoomed and panned.
Solution Primarily, RChart does not offer any polygons as drawing elements. However, you can use the event OnDataRendered to draw any number and complexity of polygons in an RChart. Following is a simple code snippet (the full program for Delphi 6 can be downloaded from http://www.lohninger.com/examples/chartpolygons.zip):

 

    const
      maxP = 10;
      RealPG : array[1..MaxP, 1..2] of double =
                   ((3,3), (4,3), (5,5), (6,2), (5,1),
                   (4,-2), (-2,-4), (-2,-1), (-1,2), (0,1));
    ..
    ..
    ..

    (*********************************************************************)
    procedure TForm1.RChart1DataRendered(Sender: TObject;
                        var Canvas: TCanvas; Top, Left: Integer);
    (*********************************************************************)

    var
      Polygon : array[1..MaxP] of TPoint;
      i       : integer;
      x,y     : integer;

    begin
    for i:=1 to MaxP do
      begin
      RChart1.R2M(RealPG[i,1],RealPG[i,2], x, y);
      Polygon[i].x := x-Left;
      Polygon[i].y := y-Top;
      end;
    Canvas.Brush.Color := clYellow;
    Canvas.Pen.Color := clBlack;
    canvas.Polygon (Polygon);
    end;

 


Last Update: 2012-11-25