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

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
BoikovSoft
Newbie
Newbie
Posts: 20
Joined: Thu Mar 26, 2009 12:00 am
Location: Russia, Samara

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

Post by BoikovSoft » Fri Nov 13, 2009 6:08 am

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]
Attachments
11.png
Picture example
11.png (61.46 KiB) Viewed 3630 times

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

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

Post by Yeray » Fri Nov 13, 2009 4:25 pm

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;
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