SAMPro
SAMPro

Reputation: 1109

Draw a pie chart with special properties (alter style and starting point)

I want to create a pie chart that has this features:

I check pie chart properties. But I don't found any corresponding feature.

I have Teechart shipped with delphi. It's v2011.03.32815. And also don't have a donut like chart. So I think it's need to coded. It' can be done by simply placing a circle on it's canvas with a color that matches to chart background.

I can use gauge component. But it does not have anti alias feature (Teechart has TeeGDIPlus ).

I've drawn an illustrator of what I mean:
enter image description here

Q1: How to draw/code a chart like so?

Upvotes: 0

Views: 5044

Answers (1)

Yeray
Yeray

Reputation: 5039

Here you have a simple example showing you how to use TeeChart to draw a TDonutSeries similar to the one in your picture. Here it is how it looks like: donut

And here it is the code I used to generate it. It's basically a TDonutSeries with 2 values and a wide pen. And two TAnnotationTools for the texts:

uses TeCanvas, TeeDonut, TeeTools, Series;

procedure TForm1.FormCreate(Sender: TObject);
var donut1: TDonutSeries;
    annot1, annot2: TAnnotationTool;
    tmpX, tmpY: Integer;
begin
  (Chart1.Canvas as TGDIPlusCanvas).AntiAliasText:=gpfBest;
  Chart1.View3D:=false;
  Chart1.Legend.Visible:=false;

  with Chart1.Foot do
  begin
    Text.Text:='G1';
    Font.Color:=clBlack;
    Font.Style:=[];
    Font.Size:=25;
  end;

  donut1:=Chart1.AddSeries(TDonutSeries) as TDonutSeries;
  annot1:=Chart1.Tools.Add(TAnnotationTool) as TAnnotationTool;
  annot2:=Chart1.Tools.Add(TAnnotationTool) as TAnnotationTool;

  with donut1 do
  begin
    Add(33, '', clWhite);
    Add(66, '', RGB(0, 178, 247));
    Pen.Color:=RGB(0, 178, 247);
    Pen.Width:=8;
    RotationAngle:=90;
    Marks.Visible:=false;
    CustomXRadius:=120;
    CustomYRadius:=120;
  end;

  with annot1 do
  begin
    Text:='56%';
    Shape.Transparent:=true;
    Shape.Font.Size:=25;
  end;

  with annot2 do
  begin
    Text:='33%';
    Shape.Transparent:=true;
    Shape.Font.Size:=15;
  end;

  Chart1.Draw;

  with annot1 do
  begin
    Shape.Left:=donut1.CircleXCenter-(Shape.Width div 2);
    Shape.Top:=donut1.CircleYCenter-(Shape.Height div 2);
  end;

  with annot2 do
  begin
    donut1.AngleToPos(180, donut1.CustomXRadius, donut1.CustomYRadius, tmpX, tmpY);
    Shape.Left:=tmpX-(Shape.Width div 2)+30;
    Shape.Top:=tmpY-(Shape.Height div 2)+30;
  end;
end;

If you prefer to use the series marks instead of TAnnotationTools, you could try setting them as follows:

  donut1.Marks.Transparent:=True;
  donut1.Marks.Font.Size:=20;
  donut1.Marks.Callout.ArrowHead:=ahSolid;

Upvotes: 4

Related Questions