Page 1 of 1

Help me to draw the circular diagramme of type of a compass.

Posted: Fri Nov 13, 2009 6:08 am
by 10552878
Hello!

Help me to draw the circular diagramme of type of a compass.

The circle is broken into 360 degrees.
The distance between labels should be regulated.
In a circle there is a sector, it should vary. For example, from 10 to 90 degrees.
There are also 5 arrows different are long. Their positions depend on their values.
[img]11.png[/img]

Re: Help me to draw the circular diagramme of type of a compass.

Posted: Fri Nov 13, 2009 4:25 pm
by yeray
Hi BoikovSoft,

I think tha tthe easier way to do it would be drawing manually both the arrows and the text. For example:

Code: Select all

uses series, TeeTools, Math;

var Series1: TPieSeries;
    LabelsIncrement: Integer;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=false;
  Chart1.Legend.Visible:=false;

  Series1:=TPieSeries.Create(self);
  Chart1.AddSeries(Series1);

  Series1.AddPie(45, '', clTeal);
  Series1.AddPie(270, '', clNavy);

  Series1.Marks.Visible:=false;
  Series1.Circled:=true;
  Series1.Shadow.Visible:=false;

  LabelsIncrement:= 90;

  Chart1.Title.Visible:=false;
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);

  procedure DrawAngleLabel(a: Integer);
  var tmpX, tmpY: Integer;
  begin
    Series1.AngleToPos(DegToRad(a), Series1.XRadius, Series1.YRadius, tmpX, tmpY);
    if a<180 then tmpY:=tmpY-12;
    if (a>90) and (a<270) then tmpX:=tmpX-Chart1.Canvas.TextWidth(IntToStr(a));
    Chart1.Canvas.TextOut(tmpX, tmpY, IntToStr(a));
  end;

  procedure DrawArrow(val: Double; angle: Integer; color: TColor);
  var tmpFrom, tmpTo: TPoint;
      tmpX, tmpY: Integer;
  begin
    Series1.AngleToPos(DegToRad(angle), Series1.XRadius*val, Series1.XRadius*val, tmpX, tmpY);

    tmpFrom.X:=Series1.CircleXCenter;
    tmpFrom.Y:=Series1.CircleYCenter;
    tmpTo.X:=tmpX;
    tmpTo.Y:=tmpY;

    Chart1.Canvas.Pen.Width:=Round(3*val);
    Chart1.Canvas.Pen.Color:=color;
    Chart1.Canvas.Arrow(false, tmpFrom, tmpTo, Round(20*val), Round(20*val), 0);
  end;

var angle: Integer;
begin
  angle:=0;

  while angle < 360 do
  begin
    DrawAngleLabel(angle);
    angle:=angle+LabelsIncrement;
  end;

  DrawArrow(0.8, 210, clRed);
  DrawArrow(0.7, 340, clGreen);
  DrawArrow(1, 300, clYellow);
  DrawArrow(0.4, 150, clYellow);
end;